【问题标题】:filename getting undefined.zip when content-disposition is set correctly正确设置内容处置时文件名得到 undefined.zip
【发布时间】:2016-09-18 04:06:12
【问题描述】:

我正在返回一个带有 httpServletResponse 的字节数组,并且 content-disposition 标头设置正确。我得到的内容也是正确的。但是有些文件名如何变得 undefined.zip。

下面是sn-p的代码:

        // set content attributes for the response
        response.setContentType("application/octet-stream"); 
        response.setContentLength((int) packageZipFile.length);  
        // set headers for the response
        String headerKey = "Content-Disposition";
        String headerValue = "attachment; filename=\"abc.zip\"";
        response.setHeader(headerKey, headerValue);

        // get output stream of the response
        outStream = response.getOutputStream();
        outStream.write(packageZipFile);  

同样在浏览器的 REST 调用响应中,它被正确设置如下。 内容处置:附件;文件名="abc.zip"

关于我做错了什么的任何建议。提前致谢!

【问题讨论】:

    标签: java http-headers


    【解决方案1】:

    我遇到了同样的问题,结果我正在访问localhost 并尝试从192.168.x.x 下载文件。这种行为在 chrome 和 firefox 中是一致的。

    这就是我在节点中设置标题的方式

    ctx.response.set('content-type', 'application/zip, application/octet-stream');
    ctx.response.set('content-disposition', `attachment; filename="filename-here.zip"`);
    ctx.response.set('filename', `filename-here.zip`);
    

    希望这可以帮助任何人在 3 年后偶然发现这个问题:)

    【讨论】:

      猜你喜欢
      • 2011-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-26
      • 1970-01-01
      • 2014-04-16
      • 1970-01-01
      相关资源
      最近更新 更多