## Install gem aws-sdk first require 'aws-sdk' require "httparty" ACCESS_KEY_ID = 'your access id to aws s3' SECRETE_ACCESS_KEY = 'your secrete access key to aws s3' BUCKET_NAME = 'Your aws s3 bucket name' s3 = AWS::S3.new(access_key_id: ACCESS_KEY_ID, secret_access_key: SECRETE_ACCESS_KEY) ## Name of file name to store in your local file_name = "#{Rails.root}/tmp/#{File.basename(User.first.avatar_url)}" File.open(file_name, "wb") do |f| ## Write file to local f.write HTTParty.get(User.first.avatar_url).parsed_response key = User.first.avatar_url.match('file_url_domain').post_match s3.buckets[BUCKET_NAME].objects[key].write(:file => file_name) end