简体   繁体   English

如何指示从Jersey中的REST服务保存到浏览器的文件名?

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

i am trying to have a REST service return a zip file from the local harddrive . 我正在尝试让REST服务从本地硬盘返回一个zip文件。 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`. 网址和http://localhost:9788/mockRESTServer/rest/interface3/123456/k123/l345我看到一个文件下载对话框,显示“你要保存文件l345`。

i want it to ask me for the zip download ie. 我想让它问我的zip下载即。 D:\\\\Documentation\\\\Documentation.zip . D:\\\\Documentation\\\\Documentation.zip But somehow it takes up the last parameter in the request URL. 但不知何故,它占用了请求URL中的最后一个参数。

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? 请参阅如何在JAX-RS中设置响应头,以便用户看到Excel的下载弹出窗口?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM