So we have Carrierwave uploading pictures to our local server. Perhaps we want the pictures stored on a third party cloud provider. Amazon S3 and Carrierwave work very well together. This blog post describes how to upload your pictures to the Amazon S3 cloud. Again, thanks to Ryan Bates and Railscasts for the great information.
In order to upload files to Amazon S3, we will be using the Fog Gem. The Carrierwave gem handles the Fog interaction with Amazon S3 behind the scenes.
- Sign up for an Amazon AWS account.
- Create a S3 bucket to store your files (photos)
- Input your credentials in:
1 2 3 4 5 6 7 8 |
|
I put my ENV variables in the Figaro Gem.
You also need to modify your code in the avatar_uploader we created in the last blog post to :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
|
That is it. Your photos are now added to your Amazon S3 bucket! Just be careful, you only get so much space on the cloud for free. In the next blog post, I will explain how to increase efficiency with a background task via Sidekiq.
Carrierwave Railscast
Uploading to Amazon S3 Railscast
Sidekiq Railscast