2

I think I'm probably just missing something in the docs here, but how do I specify that images I upload to S3 have a Cache-Control header when requested?

This answer seems to suggest you can do it by adding metadata, but the example isn't too clear. Can anyone point me to a code sample or some documentation of how I would do this in C# please?

Community
  • 1
  • 1
Mark Bell
  • 28,985
  • 26
  • 118
  • 145

2 Answers2

7

For those reading this question more recently, you can use the TransferUtilityUploadRequest's Headers.CacheControl property (Note: At the time of writing the AWS documentation doesn't make it obvious that this is an available property).

eg

// Make the upload request with the required cache and header parameters
var fileTransferUtilityRequest = new TransferUtilityUploadRequest
{
   BucketName = BucketName,
   FilePath = fileName,
   StorageClass = S3StorageClass.Standard,
   Key = keyName,
   CannedACL = S3CannedACL.PublicRead,
   ContentType = contentType,
};

fileTransferUtilityRequest.Headers.CacheControl = "max-age=604800";
var fileTransferUtility = new TransferUtility(...);
fileTransferUtility.Upload(fileTransferUtilityRequest);
mips
  • 2,137
  • 2
  • 19
  • 21
2

Well, it turns out that this is possible using the REST API for S3, but not using the SOAP methods. So the answer for me is just 'no' - unless we rewrite all our code to use the REST API.

See this AWS Support Forum post.

Mark Bell
  • 28,985
  • 26
  • 118
  • 145