Open ThiagoDosSantos opened 9 years ago
Interesting. I looked at the documentation and I couldn't find a way to set customer headers other than using metadata
(http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html). This bit of the doc (http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingMetadata.html) mentions the weird prefix that you got but doesn't mention a way to avoid them.
If you can find some doc that mentions that it's possible, please send me a link. I'd be happy to link into it.
I'm already using this custom headers in my browser app. I pass a file to a function that adds some metadata to be sent along the file to s3.
this._addMetaData = function(file){
var data = new FormData();
var randomKey= Math.floor(Math.random()*Math.pow(11, 12));
data.append('key', s3BrowseUpload.key +randomKey+ '.jpg');
data.append('AWSAccessKeyId', s3BrowseUpload.awsAccessKeyId);
data.append('Cache-Control', s3BrowseUpload.cacheControl);
data.append('x-robots-tag', s3BrowseUpload.xRobotsTag);
data.append('success_action_status', s3BrowseUpload.successActionStatus);
data.append('Content-Type', file.type);
data.append('policy', s3BrowseUpload.policy);
data.append('signature', s3BrowseUpload.signature);
// 01 file per request
data.append('file', file);
return data;
};
And it works with no problem.
Interesting! So you're just throwing the header in there and it catches it on its own? All the documentation I'm reading says it can't be done but I believe you. Let me try to remove the restrictions on the params
object to see if adding it like that works.
Well... It didn't. It's outright refused by the SDK. Do you use the official AWS SDK to upload? The only way I've read to not have the prefix is to upload through SOAP which isn't supported by the SDK. I'm not sure there's a simple solution here, sorry.
The docs that explain my implementation is here: https://aws.amazon.com/articles/1434
It says "S3 accepts uploads via specially-crafted and pre-authorized HTML POST forms. You can include these forms in any web page to allow your web site visitors to send you files using nothing more than a standard web browser"
I can't see a way to do the same thing with the SDK provided by s3. Pure rest is the unique solution to deal with that.
Thanks Mathieu!
@ThiagoDosSantos there appears to be a documented solution for this, I hope I can have a go at it sometimes this week. If you see it drags on, feel free to remind me ;)
@ThiagoDosSantos I finally got around to trying the solution I found but unfortunately it doesn't seem to be working. I reported it on the SDK repo. As soon as I have a reply I should be able to publish this change.
+1 for custom headers.
@AntonKL Currently waiting on the AWS SDK people. Their code example doesn't work.
@MathieuLoutre No stress at all. This is open and and use it for free, I have no demands what so ever. Just showing my interest in this specific feature when you decide to develop your module. Cheers!
Thanks @AntonKL, very nice of you. Will update here when I hear back from the SDK peeps :)
@MathieuLoutre , Did AWS team solve this one for us?
I haven't tried in a while but I haven't heard back since my last message. If you'd like to try @AntonKL, look at the example code here: https://github.com/aws/aws-sdk-js/issues/660
I'd like to add any header like 'x-robots-tag':'noindex' but there is no way to do that. When try using option.params.Metadata it adds a prefix 'x-amz-meta' that is not what I want. Thanks!