Approximately once\week a file upload fails when saving to Amazon S3 (1\300). The following code works well enough to confirm that the file saved correctly, but I can't help but think there's a better way. When a file does fail, no exception is thrown so I'm never really certain where the problem lies. Any suggestions for better confirmation?
AmazonS3Config _s3Config = new AmazonS3Config
{
ServiceURL = "s3.amazonaws.com",
CommunicationProtocol = Protocol.HTTPS,
};
using (AmazonS3 client = AWSClientFactory.CreateAmazonS3Client("accessKey", "secretAccessKey", _s3Config))
{
PutObjectRequest request = new PutObjectRequest();
request.WithBucketName("bucketName")
.WithFilePath("filePath")
.WithKey("keyName");
request.WithServerSideEncryptionMethod(ServerSideEncryptionMethod.AES256);
PutObjectResponse response = client.PutObject(request);
// what property from the response object can I check to confirm success???
}
// the following DoesObjectExist() function uses the GetObjectMetadata() function
if (!DoesObjectExist(keyName))
throw new Exception("Failed!");
According to the API documentation it recommends you check the ETag value against the a calculated MD5 hash of the data you sent. They obviously should match.
"To ensure an object is not corrupted over the network, you can calculate the MD5 of an object, PUT it to Amazon S3, and compare the returned Etag to the calculated MD5 value."
http://docs.amazonwebservices.com/AmazonS3/latest/API/SOAPPutObject.html
Hope that helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With