本文介绍了仅使用逗号分隔文件名中的文件下载错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的文件下载API情况下,出现这样的错误.

In my file download API case an error like this.

org.apache.catalina.connector.ClientAbortException: java.io.IOException: Broken pipe
    at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:380)
    at org.apache.tomcat.util.buf.ByteChunk.flushBuffer(ByteChunk.java:420)
    at org.apache.tomcat.util.buf.ByteChunk.append(ByteChunk.java:345)
    at org.apache.catalina.connector.OutputBuffer.writeBytes(OutputBuffer.java:405)
    at org.apache.catalina.connector.OutputBuffer.write(OutputBuffer.java:393)
    at org.apache.catalina.connector.CoyoteOutputStream.write(CoyoteOutputStream.java:96)
    at org.springframework.util.StreamUtils.copy(StreamUtils.java:128)
    at org.springframework.util.FileCopyUtils.copy(FileCopyUtils.java:109)
    at

我注意到该错误仅在尝试下载名称包含逗号(,)的文件时发生,否则它可以正常工作.

I notice that the error only occurs when trying to download a file with a name containing comma(,) otherwise it works perfectly.

在我的API中,我将响应设置如下:

In my API I set the response like this:

response.setContentType("application/octet-stream");
response.setHeader(Constants.CONTENT_DISPOSITION, "attachment; filename= " + fileSeedName);
                        System.out.println(file.exists());
                        FileCopyUtils.copy(new BufferedInputStream(new FileInputStream(file)), response.getOutputStream());
response.flushBuffer();

任何人都可以帮助我.

推荐答案

这是特定于Google Chrome的已知问题,与Content-Disposition标头相关.根据大量参考文献(仅Google的"Chrome内容处置逗号"),这是由于chrome无法正确处理逗号的转义,而Firefox,IE等却无法正确处理.根据一些网站的介绍,此功能是在最近才推出的,Google并不打算对其进行修复.

This is a known issue specific to Google Chrome specifically related to the Content-Disposition header. According to numerous references (just Google "Chrome content-disposition comma"), this is caused by the fact that chrome doesn't properly handle escaping of commas while Firefox, IE, etc. do. According to a few sites, this was introduced relatively recently and Google doesn't plan on fixing it.

参考链接

这篇关于仅使用逗号分隔文件名中的文件下载错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 21:48