tI正在嘗試研究此問題,但似乎無法找到答案。在.NET(VB.NET)我有下面的代碼刪除在Amazon S3中的對象:AWS .NET無法告訴對象是否已被成功刪除
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"
我不出來什麼是我怎麼知道該對象被成功刪除了?我認爲它會拋出異常,但事實並非如此。我可以傳遞我想要的任何密鑰,但不存在,並且它仍然可以正常工作。
嗯,我想邏輯(一個不存在的對象被刪除)是有道理的,但也許我會離開它,那麼,謝謝。 –
是的,如果文件不存在,'System.IO.File.Delete'不會拋出異常。一致的行爲是有道理的。 – vcsjones