简体   繁体   中英

Amazon S3 server side encryption

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM