Uploading a Photo to Cloud Storage from Rails

Uploading a Photo to Cloud Storage from Rails

Let’s upload a photo to Google Cloud Storage from Rails

I’ve already created a bucket, so the first thing we need to do is create a Cloud Storage access key so we can write to our bucket

We can do this by opening the Cloud Storage Interoperability settings and clicking Create a new key

Then using the Carrierwave gem, we’ll create an initializer file and add the Cloud Storage credentials we just generated to it

In our controller’s create action, we can now save our photo to Cloud Storage using the gcloud-ruby gem

We can also optionally specify the file name of the photo in Cloud Storage as a second parameter.

We’ll save the file in Cloud Storage as the current timestamp

Now, when we start our Rails server and add a new cat photo we can see it saved to our bucket

Subtitles End: http://onlinestorewebpro.com

Spread the love

Leave a Reply

Your email address will not be published. Required fields are marked *

Google Analytics Alternative