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