Episodes
Hass PRO said over 1 year ago on Direct Upload Instantly :
Great episode as usual David. How would we handle orphaned images in the case of uploading images on a new action that does not get saved? Since the images are still created and uploaded.

David Kimura PRO said over 1 year ago on Direct Upload Instantly :
Thanks   Hass  . I'm still researching how I would handle it as the current solutions that I've come up with aren't up to my satisfaction yet. I have some ideas, but not fully ready to share. The ideas that I'm bouncing around is a background job which periodically handles the orphan records. However, this imposes additional infrastructure which may not already be in place. It could also be expensive in cases where Active Storage is heavily used. I think that a better route would be to have a background job which is triggered to be performed at a later time which can then check later if the record is orphaned or not. However, this also has its own drawbacks because there could be a case where a small queue server could get overwhelmed with requests and essentially lost jobs.

Stephane PAQUET PRO said 12 months ago on Direct Upload Instantly :
I'm not sure, but it looks like the following comment in your code is no longer true

# If using Hotwire, you cannot import from @rails/activestorage
# instead, use skypack or similar to pull in active storage.

I was getting compile error using skypack and moving back to 
import { DirectUpload } from "@rails/activestorage" solved all my problems. I only have to deal with partial forms with hotwire now ;-)

Patrick PRO said 9 months ago on Direct Upload Instantly :
Nice episode! But what happens when you add presence validations to name (or email) field, and submit the form only leaving these fields blank after upload the image? I'm getting the MessageVerifier-InvalidSignature. Have any solutions for that?

Stephane PAQUET PRO said 8 months ago on Direct Upload Instantly :
  Patrick I think that "MessageVerifier-InvalidSignature" is linked to the form secret token not being properly managed. Not to validation.

Stephane PAQUET PRO said 8 months ago on Direct Upload Instantly :
  David Kimura One quick question. How would you update and existing image?

David Kimura PRO said 8 months ago on Direct Upload Instantly :
  Stephane PAQUET It should work without any modifications to this episode. I've pulled the code from this episode and updated a few things (using ruby 2.7.4, updated webpacker, updated mimemagic). These changes were really more related to my environment rather than changes required for the feature to work. No changes to the actual code and it allowed updating of existing images. Is your use case doing a has_one_attached or has_many_attached? If you have a has_many_attached situation, it becomes a bit more difficult. But, the has_one_attached works and it does clean up the previously uploaded image too.

Stephane PAQUET PRO said 8 months ago on Direct Upload Instantly :
  David Kimura thanks. 
I have a has_one_attached in my model and so far it creates a new image every time I want to update one. So I guess that I probably missed something.
I also watched episode 281, which is a great companion to this one.

Stephane PAQUET PRO said 17 days ago on Direct Upload Instantly :
Update. [not sure if this was introduced in Rails 7 or before]
Instead of hardcoding the URL in the postURL method, it is possible to use the direct_upload: true in the file field and retrieve its value calling this.inputTarget.dataset.directUploadUrl


Stephane PAQUET PRO said 15 days ago on Direct Upload Instantly :
  David Kimura I'm not sure the token is still required in Rails 7.0.2 I was building an app few days ago and found out that you can remove it...
Also, if planning to use it it seems that you can write const token = event.target.dataset.directUploadToken; inside the stimulus controller (Rails 7 required) and avoid writing an helper method to generate the token and declaring it in the form.

Login to Comment