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"
我无法弄清楚我怎么知道对象被成功删除了?我认为它会引发异常,但事实并非如此。我可以传递我想要的任何键,但是它仍然可以正常工作。
答案 0 :(得分:1)
根据此线程https://forums.aws.amazon.com/thread.jspa?threadID=60081,除非该函数抛出异常,否则该对象已成功删除。但是,如果对象不存在,文档http://docs.amazonwebservices.com/sdkfornet/latest/apidocs/html/M_Amazon_S3_AmazonS3_DeleteObject.htm确实会确认您将看到它将成功返回的行为。我想这个理论是一个不存在的对象被删除了。
在尝试删除之前,您可能必须检查对象是否存在。这个帖子https://forums.aws.amazon.com/message.jspa?messageID=219046提供了几种方法。如果对象确实存在,那么失败的删除应该抛出异常。