I'm able to delete individual files within a "Folder" on Amazon S3 using the following:
s3 = AWS::S3.new(:access_key_id => ENV['AWS_ACCESS_KEY_ID'], :secret_access_key => ENV['AWS_ACCESS_KEY'])
folder_path = 'uploads/'+@image.s3_filename
s3.buckets[ENV['AWS_BUCKET']].objects.with_prefix(folder_path).delete_all
but this leaves an empty folder. How can I just delete the folder entirely (folder_path)?
This is an old question, but you can do this for aws-sdk 2.0>
s3 = Aws::S3::Resource.new
folder = 'path/to/the/folder'
objects = s3.bucket(ENV['S3_BUCKET_NAME']).objects({prefix: folder})
objects.batch_delete!
delete
was depreciated
Hope this helps!
Everything on S3 is an object you can manipulate by its "key". If you just grab it you can call delete
on it:
s3.buckets[ENV['AWS_BUCKET']].objects["name of the folder"].delete
删除文件夹后,必须删除文件夹中的所有文件。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.