我试图研究这个,但我似乎找不到答案。在 .NET (VB.NET) 中,我有以下代码来删除 Amazon S3 中的对象:
client = Amazon.AWSClientFactory.CreateAmazonS3Client(accessKey, secretKey, RegionEndpoint.USEast1)
Dim request As DeleteObjectRequest = New DeleteObjectRequest
With request
.BucketName = bucketName
.Key = keyToDelete
End With
Try
Dim resp As DeleteObjectResponse = client.DeleteObject(request)
Dim headers As WebHeaderCollection = resp.Headers
For Each key As String In headers.Keys
Return "Response Header: " + key + "Value: " + headers.Get(key)
Next
Catch ex As AmazonS3Exception
Return "Not Deleted"
End Try
Return "Deleted"
我想不通的是我怎么知道该对象已成功删除?我以为它会抛出异常,但事实并非如此。我可以传递我想要的任何密钥,它不存在,它仍然可以正常工作。