File uploading with ActiveStorage in Rails 5.2 Discussion
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!
I'm looking into this also. Did you find a solution? I'm looking for a link to delete individual uploads.
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?
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?
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
%>
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
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:
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!
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.
Thanks!