Thursday, 5 April 2018

amazon web services - DOM Exception When trying to change Metadata on S3 using Javascript SDK

I am trying to update the content-type metadata on S3 using the AWS SDK for Javascript with the copyObject function.



The code:




var s3Client = new AWS.S3({
accessKeyId: "xxxx",
secretAccessKey: "xxxxxx"
});

var params = {
Bucket: "shareimg-temp.test.com", // required
CopySource: encodeURI('userimg-temp.test.com/uploads/' + fileName),
Key: 'uploads/' + fileName, // required

ACL: 'private', // tried without but didn't help
ContentType: 'image/jpeg',
MetadataDirective: 'REPLACE'
};


s3Client.copyObject(params, function (err, data) {
if (err)
console.log(err, err.stack); // an error occurred
else

console.log(data); // successful response
});



Error:



I am getting the following exception error from aws-sdk-2.0.0-rc10.min.js:



InvalidStateError: DOM Exception 11: An attempt was made to use an object that is not, or is no longer, usable. 



In the bucket uploads folder I do have the filename specified in the fileName. I gave full permissions (temporary just for debugging purposes).



My goal is to change the content-type to image/jpeg as when I upload it is updates with binary/octet-stream instead.



Spent hours on this and any help will be very grateful. Thanks.

No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...