使用rails从桶中删除s3对象

时间:2016-09-09 12:22:54

标签: amazon-s3

我试过这个s3.buckets[BUCKET].objects[mykey].delete来删除我的s3对象。但它没有用。当我用Google搜索时,他们已经给出了这个。什么是正确的?

1 个答案:

答案 0 :(得分:0)

那是ruby v1 - 我假设(并建议)你使用ruby sdk v2,以下代码将起作用(见http://docs.aws.amazon.com/sdkforruby/api/Aws/S3/Client.html#delete_object-instance_method

s3 = Aws::S3::Client.new(
  region: region_name,
  credentials: credentials,
  # ...
)

resp = client.delete_object({
  bucket: "BucketName", # required
  key: "ObjectKey", # required
  version_id: "ObjectVersionId" # if you enabled s3 versioning
})