1개 답변
- 최신
- 최다 투표
- 가장 많은 댓글
0
The issue you're encountering seems to be related to how TransferUtility processes the part size when uploading a stream with encryption using a CryptoStream. TransferUtility may be adding extra padding to the part size, causing a mismatch in the uploaded file's ETag.
To address this issue, you can try the following workaround:
Instead of relying on TransferUtility to calculate the part size, manually specify the part size in the TransferUtilityUploadRequest to ensure consistency. You can set the part size to 16MB + 8KB to match the behavior observed during the upload.
Here's how you can modify your code to implement this workaround:
using System.IO;
using System.Security.Cryptography;
using Amazon.S3;
using Amazon.S3.Transfer;
// Create an Aes object for encryption
Aes aesAlg = Aes.Create();
aesAlg.GenerateKey();
aesAlg.GenerateIV();
// Create an ICryptoTransform object for encryption
ICryptoTransform encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV);
// Create a CryptoStream for encryption
CryptoStream cryptoStream = new CryptoStream(input, encryptor, CryptoStreamMode.Read);
// Create an instance of AmazonS3Client
IAmazonS3 s3Client = new AmazonS3Client();
// Create a TransferUtility object with the AmazonS3Client
using var transferUtility = new TransferUtility(s3Client);
// Create a TransferUtilityUploadRequest object
var transferRequest = new TransferUtilityUploadRequest()
{
BucketName = _bucket,
Key = key,
InputStream = cryptoStream,
ContentType = "application/x-binary",
CannedACL = S3CannedACL.Private,
PartSize = (16 * 1024 * 1024) + (8 * 1024), // Set part size to 16MB + 8KB
};
// Upload the encrypted stream using TransferUtility
await transferUtility.UploadAsync(transferRequest, cancellationToken);
관련 콘텐츠
- AWS 공식업데이트됨 일 년 전