cloudinary_gem icon indicating copy to clipboard operation
cloudinary_gem copied to clipboard

Fix resource_type selection in ActiveStorage::Service::CloudinaryService

Open myacheg opened this issue 4 years ago • 1 comments

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 avatar Sep 01 '20 11:09 myacheg

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

const-cloudinary avatar Sep 13 '20 14:09 const-cloudinary

@myacheg I merged your changes in this PR (with slight modifications): https://github.com/cloudinary/cloudinary_gem/pull/508

Thank you for contribution!

const-cloudinary avatar Dec 06 '22 10:12 const-cloudinary