Skip to main content
Ask A Question
You’re not receiving notifications from this thread.

File uploading with ActiveStorage in Rails 5.2 Discussion

General • Asked by Chris Oliver
Do previewers for Word Files and Excel 

That would be awesome!

Great video Chris! You should definitely do another one on ActiveStorage integration with front-end solutions like uppy.js (or a similar one for that matter) which support many user "treats" like image thumbnails prior to uploading etc...

Yes, I agree that would be great!

Looking forward to the direct uploads/trix integration Chris! 

Regarding images attached to another model- 9 times out of 10, I have to include additional meta-data with a file upload (a title, a caption, a photo credit, etc.). Does ActiveStorage make that less of a headache in situations like a Post having multiple uploads (as you have demonstrated in this episode)? Thanks!
Good question, following...

In case of a has_many_attached setup, how would you go about creating a link to delete an individual file? 
Yes - I'd like to know this too. Can't find clear solutions elsewhere...

I'm looking into this also. Did you find a solution? I'm looking for a link to delete individual uploads.

Nice one Chris. Question about the `variant` and `preview`. Does the thumbnails will get saved into the disk or they happen on the fly? That's expensive if we do it on the fly, right? Thanks.
Variants are generated upon request (on the fly).
However, once it gets generated and saved to disk, then it is read from storage. So, the calculation only happens once.

Does anyone know if there's a way to send the preview request to a background job on upload? so something like sidekiq will handle generating and saving the preview when the file is uploaded and not waiting until a user requests the preview and making them wait?

Great Video! I'm definitely interested in seeing how you handle a slide deck. 

Hi, thanks for this helpful introduction on ActiveStorage.
Does ActiveStorage provide a solution to process uploads on upload and not on-the-fly? For ex. processing video-files could be time-consuming and good to be done on upload.
If there is no option to process on upload, is there a reason to prefer on-the-fly processing?

This is awesome! Looking forward to other preview types like keynotes etc. also what about soft delete? It’s very rare these days with work that we actually hard delete. 

Would be great to see how to use active storage with something like jquery uploader or another front end uploader, as the shrine videos are now a bit old and this could make for an interesting alternative. Plus on services like Heroku the timeout means that almost any file upload solution requires a front end fix.

Nice Episode, as always.

How does one retain an upload if the form redisplays, say if you have validation error on one of the attributes of the form model? Shrine has a Plugin for that, is there something you could do to make caching work with Active Storage?

Here is a solution that works with Rails 5.2.0:

  form.hidden_field :image, value: form.object.image.signed_id if form.object.image.attached?
  form.file_field :image

I did something like this when using direct uploads.

Hi Chris, how did you get variants to work with Mini magick? I have tried different options but continue to the get the following error: MiniMagick::Error (`mogrify -resize-to-fit [90, 90] /var/folders/mj/nv6kjryd7bncl612h_9mvvmm0000gn/T/mini_magick20180521-84072-x285ky.jpg` failed with error:
mogrify: unrecognized option `-resize-to-fit' @ error/mogrify.c/MogrifyImageCommand/5892.

I'm using mini_magick 4.8.0. Any help will be appreciated. I also tried gem "image_processing" but had the same errors.

Is this related:

Resize to fit only works with image_processing gem. Upon bundle install, restart your server and give it a try.

This worked for me:
= image_tag upload.file_attachment.variant(resize: "200x200")

Hi there, what else do I need to do that isnt in this tutorial that will show a video preview when uploaded using active storage

Thanks a lot Chris. Great stuff.
I was wondering what's the ideal way to delete/purge/destroy one or more attachments, if using Active Storage. Can you please share your ideas?

Fantastic video!

I am having no difficulties with my local setup and getting this to work. However, I am getting errors on my Heroku app on production. I watched the tutorial on Encrypted Credentials which was fantastic but unfortunately it didn't solve my issue. My storage.yml file looks like the following:

  service: S3
  access_key_id: <%= Rails.application.credentials.dig(:digitalocean, :access_key_id) %>
  secret_access_key: <%= Rails.application.credentials.dig(:digitalocean, :secret_access_key) %>
  bucket: ted-blog
  region: nyc3
  endpoint: <%= Rails.application.credentials.dig(:digitalocean, :endpoint_address) %>

    If anyone has an insight into what might be the problem, I'd be grateful.


Hello Chris, I love your videos. I was wondering if there is an easy way to upload files manually using ActiveStorage since I can not find it in the documentation. Thanks in advanced.

Am I right that a new upload copies over (or deletes) previous uploads even with had_many?

Second question. Is there any way to associate a title or caption with the uploaded image?

PS. Great video, helped me with setting up ActiveStorage. I updated to 5.2 to get AS.

I created a secondary model Attachments to add has_attached to so I could add additional fields. The issue is that there no easy way to validate the presence of an attachment. Also when my validation on the other fields fails the previously uploaded file does not seem to persist to the render :edit page.

What if I want uploading files as non-attachment?
Can't find information on ActiveStorage documentation.

Hi Oliver,

I can't get variant(size: "") to work while using a cloud provider in production.

I need to user.avatar.service_url.split("?").first to get the right path for the img but when I do this, I can't use variant because that path is a string.

Any idea how I overcome this.


Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 31,353+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.