0

I have the file location stored in the database , my file exist on that location , now I want to get that file and return it to the user. My file is not a jpg , nor pdf consider the extension as .abc.

How to return this file to the user so that user can download it , by firing the web service.

user1844840
  • 1,937
  • 3
  • 16
  • 13

2 Answers2

1

@Produces("*/*")

yourmethod(){}

Or return a javax.ws.rs.core.Response which you can set the Content-Type header programmatically

TheWhiteRabbit
  • 15,480
  • 4
  • 33
  • 57
0

You can use the Location HTTP header for this. You can set the actual path as the location header and give back the response. It is then the responsibility of the client to redirect to that URL and download.

If you want to return the contents yourself, set Content-Type as application/octet-stream and return the file contents. I assume your rest service URL would be something like http://abc/yourapp/files/<idOfYourFile>

basiljames
  • 4,777
  • 4
  • 24
  • 41
  • but what it should return I mean the byte array of the file or anything else , it is hanging for some reason ? – user1844840 Jan 29 '13 at 09:49
  • This post will help you. http://stackoverflow.com/questions/3496209/input-and-output-binary-streams-using-jersey – basiljames Jan 29 '13 at 10:59