【问题标题】:spring boot HttpServletResponse not setting file namespring boot HttpServletResponse 未设置文件名
【发布时间】:2018-04-05 19:02:09
【问题描述】:

我有这样的休息服务:

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);
            }
        }

问题是每次我调用此服务时默认保存名称都是'response',我尝试返回HttpEntity<byte[]>,创建像HttpHeaders() 这样的对象,但没有任何变化。

感谢任何帮助

【问题讨论】:

  • 你是在邮递员那里做的吗?邮递员总是要求保存带有名称响应的文档。
  • 好像是想调用服务来下载文件,有没有参考这篇帖子-download a file from Spring boot rest service
  • 对,我用的是邮递员,哦,是因为这个吗?

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


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-03-02
    • 2015-04-15
    • 1970-01-01
    • 2023-03-26
    • 2017-11-26
    • 2017-04-08
    • 2020-08-06
    • 2020-11-03
    相关资源
    最近更新 更多