How to indicate the file name for saving to the browser from a REST service in Jersey?

让人想犯罪 __ 提交于 2020-08-01 16:39:44

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!