JoHksi JoHksi - 5 months ago 12
Ruby Question

Retrieving list of files in certain folder in AWS S3(v 2.4.4) and deleting them

I'm making Angular/Rails app and upgraded Rails from 4.2.x to 5.0.0 and AWS-SDK from 1.6.x to 2.4.4.

1) I used to able to retrieve files from certain path in my AWS S3 bucket using the following syntax:

@files = @bucket.objects.with_prefix("path/to/folder")

After upgrading the AWS to the 2.4.4 version it is saying

(undefined method `with_prefix' for #<Aws::Resources::Collection:______>

I read new doc and found
bucket.objects(prefix: '/tmp-files/')
but this did not work for my appand said
ArgumentError (wrong number of arguments (given 1, expected 0))

2) Let's say I need to delete a file name
in a path
. I was doing
and not working. Is there something wrong with this syntax?


You have syntax error, options need to be a Hash. Your command should be:

bucket.objects({prefix: '/tmp-files/'})

For more options, refer docs: