Skip to content

Instantly share code, notes, and snippets.

@michelson
Created April 22, 2010 05:07
Show Gist options
  • Save michelson/374843 to your computer and use it in GitHub Desktop.
Save michelson/374843 to your computer and use it in GitHub Desktop.
def move_to_s3
temp_path = attachment.path
temp_file = attachment.to_file # Paperclips way of getting a File object for the attachment
# Save it as a regular attachment
# this will save to S3
s3_upload = Upload.find(id) # Same db record but we need the S3 version
s3_upload.attachment = temp_file # reset the file - it will assume its a new file
s3_upload.save! # Paperclip will upload the file on save
# Delete the temporary file when we are done
temp_file.close
File.delete(temp_path)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment