1
votes

I am attempting to turn on server side encryption when uploading a file asynchronously to Amazon S3. I have the file upload working but cannot figure out where to specify the encryption option. Any ideas?

using (var s3Client = new AmazonS3Client(awsAccessKeyID, awsSecretAccessKey, regionEndPoint))
{
   using (TransferUtility fileTransferUtility = new TransferUtility(s3Client))
   {
     await fileTransferUtility.UploadAsync(filePath, bucketName, objectkey);
   }
}

Edit:

I realize that Amazon has documentation on how to specify encryption using a putObjectRequest but was wondering if it can be done using the FileTransferUtility.

http://docs.aws.amazon.com/AmazonS3/latest/dev/SSEUsingDotNetSDK.html

1

1 Answers

2
votes

See http://docs.aws.amazon.com/AmazonS3/latest/dev/SSEUsingDotNetSDK.html, specifically, this:

When using the high-level multipart upload API (see Using the High-Level .NET API for Multipart Upload), the TransferUtility class provides methods (Upload and UploadDirectory) to upload objects. In this case, you can request server-side encryption using the TransferUtilityUploadRequest and TransferUtilityUploadDirectoryRequest objects.

It should be something like this (sorry, not in a place to test it at the moment):

TransferUtilityUploadRequest fileTransferUtilityRequest = new TransferUtilityUploadRequest
{
    BucketName = existingBucketName,
    FilePath = filePath,
    StorageClass = S3StorageClass.ReducedRedundancy,
    PartSize = 6291456, // 6 MB.
    Key = keyName,
    ServerSideEncryptionMethod = ServerSideEncryptionMethod.AES256
};
fileTransferUtility.UploadAsync(fileTransferUtilityRequest, someCancelToken);