-
-
Notifications
You must be signed in to change notification settings - Fork 132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Not working with not-yet-persisted blobs #242
Comments
I read your issue, tried to explore it a bit, this one is not an easy one and requires further knowledge in Do you have the ability + time to make a PR on that topic? |
I recently started encountering this issue as well after a routine Rails update. |
@northeastprince could you tell us which version of Rails did you update from/to? |
Hi @marckohlbrugge (again !), I think that we could handle this case soon. I am currently refactoring the Then I can add the corresponding tests to your case. IMO it should work because we will pass an |
I use the following to allow attaching of remote files:
This allows me to do things like:
This works as expected, but
active_storage_validations 1.1.4
does not seem compatible with this approach.The reason is that the above won't upload the photos to the cloud storage provider yet. So when we call
gallery.save!
and it runs the validations, we get anActiveStorage::FileNotFoundError (ActiveStorage::FileNotFoundError)
error inactivestorage-7.1.3/lib/active_storage/service/s3_service.rb:159:in stream: ActiveStorage::FileNotFoundError
After a little digging, I found out the reason for this:
active_storage_validations/lib/active_storage_validations/metadata.rb
Lines 74 to 84 in dd835e6
This code assumes the
blob
is already saved and uploaded. However, with the above code example, the blob will not be persisted yet. Soblob.id
will benil
andblob.download
raises the exception.Here's a relevant code comment from activestorage/lib/active_storage/attached/many.rb and activestorage/lib/active_storage/attached/one.rb's
attach(…)
methods:So it seems to be that approach from my
ActiveStorage::RemoteURLHelper
mixin is indeed a valid use of the ActiveStorage API's, butactive_storage_validations
is currently incompatible with the scenario where the blobs aren't persisted yet.Unfortunately, I don't see an easy solution as
ActiveStorageValidations::Metadata
is only passed the file (a blob in this case), and an unsaved blob, as far as I know, does have no knowledge of itsio
as that's typically passed in externally right before it gets uploaded.The proper approach might be to not pass the blob, but the
ActiveStorage::Attached::One
/ActiveStorage::Attached::Many
instead.The text was updated successfully, but these errors were encountered: