'S3 Presigned URL Multiple Content Disposition Headers

I have an S3 bucket having PDF files as objects and all of them are private. I create an S3 Presigned URL programmatically to get the object. It works fine. Now, I want it to be previewable as a PDF. Every object already has a Content-Type header set to application/pdf. Now, if I set the response-content-disposition header as a query parameter, it gets set but doesn't override the already existing Content-disposition header, instead, it creates a new one. If I set the Content-Disposition header in the metadata of the S3 object instead of adding it in the S3 Presigned URL as a query parameter, it still shows 2 headers. Is this some kind of bug on the AWS S3 side?

Below is the screenshot of the Response Header for reference.

Con

Any help will be much appreciated. Thanks.



Solution 1:[1]

It's strange how often we overlook things like filenames where comma (,) could be common if it is user generated name. While setting response-content-disposition make sure to strip special character or properly escape the filename attribute

Refer https://stackoverflow.com/a/6745788/8813684 for more details

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Naresh Kumar