In AWS SDK for PHP v3 the method putObject can receive many parameters like ContentType, ContentEncoding, etc.

In it's simplest form, I can put a object using only Bucket, Key and SourceFile:

$result = $s3->putObject(array('Bucket' => $bucket,'Key' => $keyname,'SourceFile' => $filepath));

Considering that my app is going to insert photos and they must stay in S3 until I order to delete it, what are the pros and cons of setting metadata on them, like ContentType, ContentEncoding and others?

Will it's simplest form passing only Bucket, Key and SourceFile attend my goals?

2

Best Answer


Will it's simplest form passing only Bucket, Key and SourceFile attend my goals?

The answer is Yes it will serve your purpose but if you use Metadata then you can have more control over your object.

According to AWS documentation about Object Metadata,

There are two kinds of Meta data:

  • System metadata : Metadata such as object creation Date, Last-Modified, Content-Length are system controlled where only Amazon S3 can modify the value.

  • User-defined metadata : You can set/modify optional information as a name-value (key-value) pair when you send a PUT or POST request to create the object and you can grab them in future also.

Use Case:

If you have your bucket configured as a website, sometimes you mightwant to redirect a page request to another page or an external URL. Inthis case, a web page is an object in your bucket. Amazon S3 storesthe page redirect value as system metadata whose value you control.When you create objects, you can configure values of these systemmetadata items or update the values

For more info about Object Meta Data,

http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingMetadata.html#object-metadata

You have system metadata and user metadata.

You can just stick to using bucket and key name only.However depending on your application logic user-metadata comes in handy in various cases.For example you can add extra information such as the username of the person that uploaded the original version of the file.

However be aware of the limitations and don't overdo it.

The PUT request header is limited to 8 KB in size. Within the PUT request header, the user-defined metadata is limited to 2 KB in size. The size of user-defined metadata is measured by taking the sum of the number of bytes in the UTF-8 encoding of each key and value.