我想用aws-sdk
删除从我的S3存储一个文件,但至今没有运气... AWS S3 delete_object
方法返回DeleteObjectOutput
结构所有nil
属性:如何从Amazon S3中删除对象?
#<struct Aws::S3::Types::DeleteObjectOutput delete_marker=nil, version_id=nil, request_charged=nil>
但后来当我检查的文件夹我的桶中的目录我可以看到一个文件仍然存在。
代码如下。
的Gemfile
gem 'aws-sdk', '~> 2'
配置/初始化/ AWS-sdk.rb
Aws.config.update({
region: 'us-west-2',
credentials: Aws::Credentials.new(
ENV['AWS_ACCESS_KEY_ID'],
ENV['AWS_SECRET_ACCESS_KEY'])
})
my_controller.rb
s3 = Aws::S3::Client.new
response = s3.delete_object({
bucket: ENV['S3_BUCKET_NAME'],
key: params[:attachment_url]
})
# response == <struct Aws::S3::Types::DeleteObjectOutput delete_marker=nil, version_id=nil, request_charged=nil>
你的URL可能是错误的。 – djechlin