title: Is it possible to control the filename for a Response from a Jersey Rest service?
body: <p>Currently I have a method in Jersey that retrieves a file from a content repository and returns it as a Response. The file can be a jpeg, gif, pdf, docx, html, etc. (basically anything). Currently, however, I cannot figure out how I can control the filename since each file downloads automatically with the name (download.[file extension] i.e. (download.jpg, download.docx, download.pdf). Is there a way that I can set the filename? I already have it in a String, but I don't know how to set the response so that it shows that filename instead of defaulting to "download". </p>
  
  <pre><code>@GET
  @Path("/download/{id}")
  public Response downloadContent(@PathParam("id") String id)
  {
      String serverUrl = "http://localhost:8080/alfresco/service/cmis";
      String username = "admin";
      String password = "admin";
  
      Session session = getSession(serverUrl, username, password);
  
      Document doc = (Document)session.getObject(session.createObjectId(id));
  
      String filename = doc.getName();
  
      ResponseBuilder rb = new ResponseBuilderImpl();
  
      rb.type(doc.getContentStreamMimeType());
      rb.entity(doc.getContentStream().getStream());
  
      return rb.build();
  }
  </code></pre>