Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9165303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:52:42+00:00 2026-06-17T14:52:42+00:00

Hello i’m trying create an application allowing me host any kind of file. In

  • 0

Hello i’m trying create an application allowing me host any kind of file.
In order to do it i’m exececuting following magic:

@RequestMapping(value = "/files/{file_name}", method = RequestMethod.GET)
    @ResponseBody
    public FileSystemResource 
    getFile(
            @PathVariable("file_name") String fileName) {
        System.out.println(fileName);
        String filePath = "./files/";
        return new FileSystemResource(new File(filePath+fileName)); 
    }

But this approach brings three unwanted problems:

  1. Some random data is beeing appended to the file

  2. The file gets opened in the browser window instead of beeing
    downloaded – i’ve tried to hack this using something like

    produces = “application/octet-stream”

    but it only resulted in 406 error.

  3. The test.txt is beeing truncated into test, i found a walkaround in providing the app with test.txt/ as fileName but it looks a bit messy.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T14:52:43+00:00Added an answer on June 17, 2026 at 2:52 pm

    As stated on spring manual

    As with @RequestBody, Spring converts the returned object to a
    response body by using an HttpMessageConverter

    I think your problem is spring doesn’t come with a HttpMessageConverter than can process FileSystemResource.

    A list of builtin HttpMessageConverter is available here. I suggest you try converting your response into byte array somehow, maybe it will pick ByteArrayHttpMessageConverter instead and help solve your issue

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I use the following code in order to retrieve an events infoormation from
Hello I am trying to implement a wake lock for an application. PowerManager pm
Hello all in my iphone application after sending login xml request am getting following
Hello I am trying to read a file in Python 8 lines at a
Hello ! I need to create a report like the attachment shows with Jasper
Hello i'm doing a application in php, and i have a list of items
Hello I am trying to get status of battery of the device programmatically. So
Hello I have following column in SSRS Report. Column Name(Title) Mehta, Natasha(18)----its Title+(count) value
Hello I want to get Accurate location so that i have used following link
hello evrey body i have try really hard to write a file to android

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.