Why choose us Know us deep, try our developers before you hireILE & CLOUD for 13 strong years!!! Let's Discuss
Know our success stories Have a look at our works, get satisfied and then decide upon us to hire View More
Why choose us Know us deep, try our developers before you hireILE & CLOUD for 13 strong years!!! Let's Discuss
Know our success stories Have a look at our works, get satisfied and then decide upon us to hire View More
How do I check if a file exists in AWS S3 bucket using Rails3 by Jayadev Das T T T T April 18, 2013June 12, 2021 Stay up to date with the latest tips and techniques of web and mobile app development services. Please leave this field empty Thanks for subscribing Andolasoft Blog! Introduction Amazon S3 provides a simple web services interface that can be used to store and retrieve any amount of data, at any time, from anywhere on the web. While uploading a file to S3 we need to check whether the file exists to avoid any data duplication. Steps to check the presence of a file Step#1 Add the below in your gem file, gem 'aws-s3' Then run the bundle, bundle install Step#2 Modify your model as, require 'aws/s3' def is_file_exist? AWS::S3::Base.establish_connection!( :access_key_id => 'S3_KEY', :secret_access_key => 'S3_SECRET') return AWS::S3::S3Object.exists? attachment_id, "<YOUR_BUCKET_NAME>” end It is preferred to have the s3 credentials on the config folder and use it from the config file. Step#3 Now modify your controller where you want to check the existence of the file, current_user.is_file_exist? #return true if exists Easy method to avoid data redundancy in secured AWS S3. Read Also: How to use Amazon S3 Bucket with Paperclip to store images in Rails3 I hope you find this useful. If you want to develop application in rails or want to deploy app in AWS cloud, then Andolasoft is the ideal and cost savvy option for you. Have something to add to this topic? Share it in the comments. Related Posts: How to use Amazon S3 Bucket with Paperclip to store images in Rails3 Top Reasons To Choose Amazon Web Services To Grow Your Business How to cut down Amazon Web Services (AWS) billing?