Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

File download error only in file name with Comma

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.

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

Can anyone please help me.

like image 885
Mr. Sha Avatar asked Dec 07 '22 15:12

Mr. Sha


1 Answers

Wrap the filepath in "Double Quotes"

like image 163
Ahmad Faiq Ateel Avatar answered Dec 24 '22 18:12

Ahmad Faiq Ateel