1

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:

However, it's not solving my purpose. I have the following questions:

  1. Is it possible to send message data (like subject, message, message id, etc) along with the attachments (Inputstream) in one response?
  2. 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?
  3. How to send the file data in the response?

Any pointers appreciated. TIA.

Community
  • 1
  • 1
Pramod Karandikar
  • 5,289
  • 7
  • 43
  • 68

1 Answers1

1
  1. You can add custom data to the response Header, so yes you are able to send such message data. Add the data to the response Header.

  2. @Produces(MediaType.APPLICATION_JSON) will not work, unless the clients will accept JSON as a file, what they should and will not do ;)

    The correct MediaType depends on what kind of file you want to submit.

    You can use the default MediaType / MIME-Type MediaType.APPLICATION_OCTET_STREAM / application/octet-stream (Is there a “default” MIME type?) but I think it's better to use the correct and exact MIME-Type for your file.

  3. You will find working examples for sending file data with jersey in Input and Output binary streams using JERSEY? - so there is no need to answer this again :)

Hope this was helpful somehow, have a nice day.

Community
  • 1
  • 1
zyexal
  • 1,570
  • 16
  • 23