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?

2 Answers 2

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);
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.