Connecting to AWS with Fog Ruby Gem
With our Carrierwave uploader in place and our credentials saved securely, it's now time to create our AWS S3 API connector.
Guide Tasks
  • Read Tutorial
  • Watch Guide Video
Video locked
This video is viewable to users with a Bottega Bootcamp license

With our Carrierwave uploader in place and our credentials saved securely, it's now time to create our AWS S3 API connector.

To do this, go to the initializers folder inside your config directory. Right click on the folder, create a file and save it as fog.rb. This is the code that needs to be typed in.

large

In the first line, we are calling the built-in configure method of CarrierWave class. We are starting our code block, and inside this we are setting up our fog credentials, fog directory and whether we want the file to be public or not.

Inside the credentials method, we are setting up our provider, access key id and secret access key. The values to the keys are getting passed through our ENV or environment variable. So, the code will go to environments and get this information from the application.yml file. Likewise, it will get our bucket values also from the same file.

That's it! Now, you're all set to connect to AWS using Fog.