문제

Basically I need to provide REST service that would receive a String param, use that param to fetch a file from another system and then return the fetched file back as the response.

The effect should be the same as when a user clicks on a pdf or any other binary file link and the browser prompts him to save/download that file.

A couple of points:

  • is it possible to stream the file (to send bytes as I receive them from source system). In other words, how to handle very large files?
  • also related to streaming, when using regular HttpServletResponse, do I have to wait until a large file is completely read to return response.build()?

How do I go around doing this using Apache Wink?

PS Sorry, this may be trivial for Wink gurus, but I'm just starting to wrap my head around developer guide.

도움이 되었습니까?

해결책

You can just return the java.io.File from your method. You can wrap it with Response if you like. Wink will handle the streaming. The streaming doesn't start when you call to response.build(), but rather when your method finishes.

If you want a correct download dialog, you should return the proper Content-Disposition header. See How to set response header in JAX-RS so that user sees download popup for Excel?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top