gpt4 book ai didi

c# - Amazon S3 PutObject() 返回值确认成功?

转载 作者:太空狗 更新时间:2023-10-29 23:09:19 27 4
gpt4 key购买 nike

在保存到 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!");

最佳答案

根据 API 文档,它建议您根据所发送数据的计算 MD5 哈希检查 ETag 值。他们显然应该匹配。

“为确保对象不会在网络上损坏,您可以计算对象的 MD5,将其放入 Amazon S3,并将返回的 Etag 与计算出的 MD5 值进行比较。”

http://docs.amazonwebservices.com/AmazonS3/latest/API/SOAPPutObject.html

希望对你有帮助

关于c# - Amazon S3 PutObject() 返回值确认成功?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12454305/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com