0

I'm using the aws-sdk gem and trying to verify if a file uploaded to a bucket exists. I'm also using Paperclip 2.7.

This method seems to not work:

if record.image and AWS::S3::S3Object.exists? record.image, "mybucket-dev"

I think AWS::S3::S3Object.exists? was a method from old gem aws-s3 ?

What method can I use to test if the file is present in the bucket ?

In fact, the real path I want to check is something like that:

record.image.to_file(:tiny).path 

(the tiny version of my image)

Thanks.

4 Answers 4

3

Try this

AWS::S3.new.buckets["bucket"].objects["file path on s3"].exists?

The above code will return true if the file exists else returns false.

For your future reference please refer http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/S3/S3Object.html#

Hope this helps.

0

try see this document

http://rubydoc.info/github/stesla/fog/Fog/AWS/S3:head_object not sure it help, this is using Fog

0

Please try this

obj = AWS::S3::Bucket.find("bucket_name")

obj.objects[object_name].exists?

This would return true or false.

OR

AWS::S3::S3Object.exists? "path to file", "bucket_name"

0

Aws::S3::Object.new(region:'ap-southeast-1', credentials: 'cred', key: 'key', bucket_name: 'bucket').exists?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.