Ask A Question

Notifications

You’re not receiving notifications from this thread.

File uploading with ActiveStorage in Rails 5.2 Discussion

Do previewers for Word Files and Excel 
Reply

That would be awesome!

Reply
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...
Reply
Yes, I agree that would be great!
Reply
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!
Reply
Good question, following...
Reply
In case of a has_many_attached setup, how would you go about creating a link to delete an individual file? 
Reply
Yes - I'd like to know this too. Can't find clear solutions elsewhere...
Reply

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

Reply
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.
Reply
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.
Reply

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?

Reply
Great Video! I'm definitely interested in seeing how you handle a slide deck. 
Reply
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?
Reply
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. 
Reply
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.
Reply
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?
Reply

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
%>
Reply

I did something like this when using direct uploads.

Reply
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: https://github.com/janko-m/image_processing/issues/39

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

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

Reply
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
Reply

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?

Reply

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:

digitalocean:
  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.

    Thanks!
Reply

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.

Reply

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.

Reply

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.

Reply

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

Reply

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.

Thanks!

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 87,563+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.