保存到 Amazon S3 (1\300) 时,大约每周一次文件上传失败。以下代码可以很好地确认文件保存正确,但我不禁想到有更好的方法。当文件确实失败时,不会引发异常,因此我永远无法确定问题出在哪里。有什么更好的确认建议吗?
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!");