问题
i am trying to have a REST service return a zip file from the local harddrive . Following is what i am doing ,
@Path("/interface3/{Ent_id}/{esf_app_id}/{esf_app_ver}")
public class Interface3Mock {
// This method is called if TEXT_PLAIN is request
@GET
@Produces("application/zip")
public Response callInterface3_text(
@PathParam("Ent_id") Integer entitlement_id,
@PathParam("eapp_id") String eapp_id,
@PathParam("eapp_ver") String eapp_ver) {
File f = new File("D:\\Documentation\\Documentation.zip");
String mt = new MimetypesFileTypeMap().getContentType(f);
return Response.ok(f, mt).build();
}
}
Now when i use the browser ie. Internet Explorer and key in the url http://localhost:9788/mockRESTServer/rest/interface3/123456/k123/l345
i see a file download dialog that says "Do you want to save the file l345`.
i want it to ask me for the zip download ie. D:\\Documentation\\Documentation.zip
.
But somehow it takes up the last parameter in the request URL.
回答1:
return Response.ok(f, mt)
.header("Content-Disposition", "attachment; filename=Documentation.zip")
.build();
See How to set response header in JAX-RS so that user sees download popup for Excel?
来源:https://stackoverflow.com/questions/6850642/how-to-indicate-the-file-name-for-saving-to-the-browser-from-a-rest-service-in-j