http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#copyObject-property
Updating ContentType is so confusing as it requires to pass MetadataDirective to REPLACE
I lost a lot of time to figure out why passing ContentType alone doesn't have any effect.
I find out how to do with this answer : https://github.com/aws/aws-sdk-php/issues/717#issuecomment-165298178
I think the doc (not only JavaScriptSDK) should say that ContentType is considered as a metadata and not a simple header.
Summary :
For reference, this is a copyObject call that changes the content type of an object:
s3.copyObject({
Bucket: bucket,
Key: key,
CopySource: `${bucket}/${key}`,
ContentType: newContentType,
MetadataDirective: 'REPLACE'
})
@denisw
Thank you. The MetadataDirective worked perfectly!
Similarly it is equally confusing when you just want to update the metadata and thus pass MetadataDirective = REPLACE but then you lose the original ContentType if you don't explicitly set that in the copy again as well.
Would be amazing if the docs could be updated to mention what happens if the MetadataDirective is not present and what's the default value? I think is ok as is, just more clear docs would be appreciated :+1:
+1, I lost a couple of hours wondering why Content-Disposition was not getting applied. It's been three years, come on
+1
On the broader topic of updating metadata efficiently without rewriting the object content, I'm looking at this again after a couple of years, and I see there is no information in the S3 User's Guide or the detailed JavaDoc about this seemingly obvious use case. Am I missing something?
Doing a Google search returns a tremendous amount of lore and speculation for the Java and Boto client SDKs covering a period of several years, none of which seems definitive.
+1
+1
Most helpful comment
For reference, this is a
copyObjectcall that changes the content type of an object: