spring boot HttpServletResponse没有设置文件名

时间:2017-10-24 20:45:45

标签: spring-boot java-8 apache-poi content-disposition

我有这样的休息服务:

import org.apache.tomcat.util.http.fileupload.IOUtils;

    @RequestMapping(value = "/xxx", method = GET)
    public void getExcel(HttpServletResponse resp) {
     resp.setHeader("Content-Disposition", "attachment; filename=\"NAME.xlsx\"");
     resp.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");

            try (ServletOutputStream outputStream = resp.getOutputStream()) {
                IOUtils.copy(A-VALID-FILE-INPUT-STREAM, outputStream);
                resp.flushBuffer();
            } catch (IOException e) {
                throw new AppException(e);
            }
        }

问题在于,每次我调用此服务时,默认保存名称都是&#39; 响应&#39;,我尝试返回HttpEntity<byte[]>,创建像{{{}这样的对象1}}但没有任何改变。

感谢任何帮助

1 个答案:

答案 0 :(得分:0)

如果您正在使用邮递员,请查看https://github.com/postmanlabs/postman-app-support/issues/2082

似乎您需要等到邮递员团队解决此问题。