删除S3对象

时间:2012-01-14 18:15:16

标签: c# amazon-s3 amazon-web-services

我正在使用.net,我正在尝试从S3存储桶中删除一个对象。 我尝试了以下方法:

Amazon.S3.AmazonS3Client client = new Amazon.S3.AmazonS3Client(Properties.Settings.Default.AmazonS3VideoSrcKey, Properties.Settings.Default.AmazonS3VideoSrcSecret);
client.DeleteObject(new Amazon.S3.Model.DeleteObjectRequest() { BucketName = "xxxx", Key = "http://....../filename"});

我不会让IsDeleteMarker成真。

有什么不对?

感谢

2 个答案:

答案 0 :(得分:12)

你的密钥是否有http:// ...前缀?

我的猜测是你错误地传递了一个URL而不是一个键。 您的请求应该看起来更像这样:

client.DeleteObject(new Amazon.S3.Model.DeleteObjectRequest() { BucketName = "xxxx", Key = "filename"});

答案 1 :(得分:-2)

ListVersionsResponse listResponse = client.ListVersions(new ListVersionsRequest { 
    BucketName = bucketName, 
    Prefix = keyName }
);
List<S3ObjectVersion> listversion = listResponse.Versions;

foreach (S3ObjectVersion VersionIDs in listResponse.Versions)
{
    if(VersionIDs.IsDeleteMarker)
    {
        DeleteObjectRequest request = new DeleteObjectRequest
        {
            BucketName = bucketName,
            Key = keyName,
            VersionId = VersionIDs.VersionId
        };
        client.DeleteObjectAsync(request);
    }      
}