engg
engg

Reputation: 35

S3 Presigned URL - filename provided in Content Desposition for generating Presigned URL, getting error while downloading

Trying to download a file from AWS S3 using presigned Url , and i set the file name in Content Desposition. The file name is having comma " , " . while i tried downloading this file using that presigned URL, got this error in Browser ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION. Here is my java code.

ResponseHeaderOverrides override = new ResponseHeaderOverrides();
       
             
        override.setContentDisposition("attachment; filename="+ "BM, EN-POP, SWP - 8P GUK A.pptx");
        GeneratePresignedUrlRequest generatePresignedUrlRequest = new GeneratePresignedUrlRequest(Bucket_name,S3_Object)
             .withMethod(HttpMethod.GET)
             .withExpiration(expiration)
             .withResponseHeaders(override);`

the Generated presigned URl is:

https://BUCKETNAMEamazonaws.com/S3OBJECT?response-content-disposition=attachment%3B%20filename%3DBM%2C%20EN-POP%2C%20SWP%20-%208P%20GUK%20A.pptx&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20200914T142744Z&X-Amz-SignedHeaders=host&X-Amz-Expires=56&X-Amz-Credential=AKIA6HDPIVH2Z7PVP4SY%2F20200914%2Fap-south-1%2Fs3%2Faws4_request&X-Amz-Signature=1095c99c6d9ad83a9d14d2af89d064ac420783f6a58f0071537b4d623d02d546

Anyone having any idea, the comma in the filename mentioned in content-Desposition can not be replaced.

Upvotes: 1

Views: 2281

Answers (1)

kwarter
kwarter

Reputation: 21

Recommended syntax for the Content-Disposition header is to surround the filename with quotes.

Content-Disposition: inline
Content-Disposition: attachment
Content-Disposition: attachment; filename="filename.jpg"
Content-Disposition: attachment; filename*="filename.jpg"

The quotes around the filename are optional, but are necessary if you use special characters in the filename, such as spaces.

Source: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition#syntax

Upvotes: 1

Related Questions