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