5

I have stored images that users upload on AWS S3. When a user views those images in the browser, they have urls that point to my app, where I redirect to a temporary signed url using s3.getSignedUrl. Everything works great 99% of the time.

The issue is that once in a while a user will upload an image that has a comma in the filename. When they then try and view that image in Chrome (and only chrome), I get this error

net::ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION

I figured out that it was the comma since several other people are having a similar problem which they fixed by setting the content-disposition header.

With s3 and getSignedUrl, this can, I think, be done by setting the ReponseContentDisposition attribute in the params argument. The specific fix is to either properly quote the filename in the content-disposition or to just set the filename to something else that doesn't contain a comma at all.

That plan, however, isn't working for me. Anyone have any ideas about the details I might be getting wrong?

My server is Node.js. Here is the js that is doing the redirect (which like I said normally works great)

function tempRedirect(req, res) {
    var filename = req.params[0];
    var params = {
        Bucket: S3_BUCKET,
        ResponseContentDisposition: 'inline; filename=' + filename.replace(/,/, '_'),
        Key: checkTrailingSlash(getFileKeyDir(req)) + filename
    };
    var s3 = new aws.S3(s3Options);
    s3.getSignedUrl('getObject', params, function(err, url) {
        res.redirect(url);
    });
};
Community
  • 1
  • 1
eagspoo
  • 2,095
  • 3
  • 22
  • 31
  • 1
    Tried adding `g` flag to `RegExp` `/,/g`? – guest271314 Jul 12 '16 at 06:06
  • Here is the "response-content-disposition" query string parameter from chrome inspector: response-content-disposition:inline; filename="test,_2.jpg" as an example of one option I tried that didn't work (quoting the filename) – eagspoo Jul 12 '16 at 06:06
  • @guest271314 just tried. I was pretty sure there was only one comma but good catch still. Here is the "response-content-disposition" query string when I'm trying to remove the commas: response-content-disposition:inline; filename=test__2.jpg – eagspoo Jul 12 '16 at 06:08

1 Answers1

0

This is a regression in S3.

AWS Developer Forum - response-content-disposition parameter is not working in S3 GET request

eagspoo
  • 2,095
  • 3
  • 22
  • 31