cloudinary_gem
cloudinary_gem copied to clipboard
Fix resource_type selection in ActiveStorage::Service::CloudinaryService
Co-authored-by: Egor Oleynik [email protected]
Brief Summary of Changes
We ran into an issue with the direct upload of NOT images.
Gem is not recognizing resource type and we always get links with /image/
part.
It works on production. But it is not working in development.
After investigation, we found the source of the issue.
It happens because gem using monkey patching for ActiveStorage::Blob#key
.
We start using content_type from ActiveStorage arguments. ActiveStorage always provides a content type in options for url_for_direct_upload
method and we can rely on it. Here is a link to rails source code
What does this PR address?
[ ] Gitub issue (Add reference - #XX) [ ] Refactoring [ ] New feature [x] Bug fix [x] Adds more tests
Are tests included?
[X] Yes [ ] No
Reviewer, Please Note:
@myacheg , it looks a bit strange that existing code works in production, but does not work in development.
We do patch ActiveStorage::Blob#key
, so effectively we get the same content_type
, but from the attributes
of the key.
Please provide more details of the issue you are experiencing in your development environment.
@myacheg I merged your changes in this PR (with slight modifications): https://github.com/cloudinary/cloudinary_gem/pull/508
Thank you for contribution!