Incoming image transformations with Rails Active Storage
I have configured Active Storage to work with Cloudinary for image uploads following the documentation (https://cloudinary.com/documentation/rails_activestorage#direct_uploads). Now I would like to set it up so all the images uploaded from my app are resized to a certain maximum width / height in px before being stored.
I have seen here https://cloudinary.com/documentation/transformations_on_upload#incoming_transformations, that you can achieve this by configuring the 'upload' . However, this is not how I upload pictures, I upload them through form fields and Active Storage. How could I implement the incoming transformations in my situation?
-
Hi Victor,
There are two ways to achieve that. The first would be to create an upload preset in the Media Library configuration, set the incoming transformation you need in the Upload Manipulations tab, save the preset and then set that upload preset as a default upload preset for images - https://support.cloudinary.com/hc/en-us/articles/208097215-How-can-I-add-upload-options-when-uploading-via-the-Media-Library-. Using this approach you won't need any changes in your Rails code as the preset will be applied automatically at upload time for all images.
The second way would be to use the `config/storage.yml` file to pass upload parameters. For example, if you do uploads from other SDKs/services and you don't want to set the upload preset as a default for all images (point 1) then you can configure the `upload_preset` in the `storage.yml` and it'll be passed with the upload requests. For example, passing a folder, tags using that approach - https://github.com/cloudinary/cloudinary_gem/blob/b92859b4a7fa6c72176f33d48ff2e5f317a078ce/spec/active_storage/service/configurations.yml
Please sign in to leave a comment.
Comments
1 comment