0
votes

I'm using Rails 5.2 and GCS as cloud service. I'd like to give an opportunity to users to crop and rotate user's image. User has many Images, Image has one :image_file attached

In development I use such method:

class Image

...

  def  rotate(degree)
    image =  MiniMagick::Image.new(ActiveStorage::Blob.service.send(:path_for, self.image_file.key))
    image.rotate "#{degree}"
    image.write(ActiveStorage::Blob.service.send(:path_for, self.image_file.key))
    self.image_file.blob.analyze
  end

...

end

But I can't figure out how to get to image files in cloud.

I've made it to download the file to local storage and make all the operations needed.

Now it takes only to replace (delete current and create a new one with the same name) the file in the cloud (without changing anything in the database records if possible), but I can't figure out how to do this with active storage.

At least I need to get the file name in the cloud to use just bare google-cloud-ruby

1

1 Answers

0
votes

To list files stored in Cloud Storage bucket using Ruby on Rails see the code example defined here. You can also upload files to cloud storage bucket and delete files from them using Ruby on Rails.

Also since you are allowing your customers to modify their files in Cloud Storage buckets, you may consider using versioning. This will incur you additional cost but will provide reliability for your customers.

Here is the link to Ruby on Google Cloud Platform documentation which might be helpful to you.