Search code examples
ruby-on-railsrails-apirails-activestorage

Rails active_storage with rails api


I'm using rails 5.2 api and active_storage

I know when you are using full fat rails in your views you can do stuff like

image.file.upload.variant(resize: "100x100")

But since im using the api version, how can I get the url for this? does anyone know of documentation that covers using active storage in an api?

FYI, I already tried url_for(image.file.upload.variant(resize: "100x100")) it doesn't work.

At this point, Im kinda tempted to go back to paperclip.


Solution

  • I'm not really sure since I haven't use ActiveStorage much yet, but try this .processed.service_url from the docs https://api.rubyonrails.org/v5.2.0/classes/ActiveStorage/Variant.html

    For what I understand, the first time you call that it creates the variant and uploads it, then it stays there and the next time it just gets the url.