Created
November 2, 2010 12:02
-
-
Save jrom/659539 to your computer and use it in GitHub Desktop.
For downloading assets (in this case Paperclip attachments) from S3 to local filesystem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'aws/s3' | |
AWS::S3::Base.establish_connection!( | |
:access_key_id => 'id', | |
:secret_access_key => 'secret' | |
) | |
missing_uploads = [1,2,3,4] # ID's from the attachments you want to download | |
log = File.open('file-import-log.txt','w') | |
bucket = AWS::S3::Bucket.find('bucket-name'); nil | |
missing_uploads.each do |id| | |
bucket.objects(:prefix => "assets/#{id}/").each do |o| | |
`mkdir -p #{File.dirname(o.key)}` | |
open(o.key, 'w') do |file| | |
AWS::S3::S3Object.stream(o.key, o.bucket.name) do |chunk| | |
file.write chunk | |
end | |
end | |
end | |
log.write "#{Time.now} Downloaded asset #{id}\n" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment