How do I specify a file name to save in a browser from a REST service in Jersey?

I am trying to return a REST service to a zip file from a local hard drive. The following is what I do

@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, i.e. Internet Explorer and the key in the URL http://localhost:9788/mockRESTServer/rest/interface3/123456/k123/l345 I see a file download dialog box that says: "You want to save the l345` file.

I want him to ask me to download zip, i.e. D:\\Documentation\\Documentation.zip . But for some reason, it takes the last parameter in the request URL.

+6
source share
1 answer
 return Response.ok(f, mt) .header("Content-Disposition", "attachment; filename=Documentation.zip") .build(); 

See How do I customize the response header in JAX-RS for the user to see the download popup for Excel?

+9
source

Source: https://habr.com/ru/post/893719/


All Articles