I am working on a use case where I am displaying user's messages on a JSP. Details of the flow are:
- All the messages will be shown in a table with icon for attachments
- When the user clicks on attachment, the file should get downloaded.
- If there is more than one attachment, user can select the required one to download.
- The attachments will be stored on the local filesystem and the path for the attachments will be determined by the system.
I have tried to implement by referring to these SO questions:
- Input and Output binary streams using JERSEY?
- Return a file using Java Jersey
- file downloading in restful web services
However, it's not solving my purpose. I have the following questions:
- Is it possible to send message data (like subject, message, message id, etc) along with the attachments (Inputstream) in one response?
- If yes, what needs to be the
MediaType
for@Produces
annotation in my resource method? Currently my resource is annotated with@Produces(MediaType.APPLICATION_JSON)
. Will this work? - How to send the file data in the response?
Any pointers appreciated. TIA.