Aws-sdk-js: Better documentation for AWS.S3.copyObject on updating ContentType

Created on 10 Aug 2016  路  9Comments  路  Source: aws/aws-sdk-js

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 :

  • There is a Metadata, a ContentType and a MetadataDirective field
  • If I only pass a ContentType nothing appends.. Not even an error
  • Even I don't pass Metadata, I have to pass MetadataDirective in order to update ContentType
  • ContentType update does not have the same behaviour as other header (eg ContentEncoding)
documentation service-api

Most helpful comment

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

All 9 comments

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

Was this page helpful?
0 / 5 - 0 ratings