cloudinary / cloudinary_gem

Cloudinary GEM for Ruby on Rails integration
https://cloudinary.com
420 stars 285 forks source link

Include contextual metadata when using url_for_direct_upload #535

Closed jaydorsey closed 6 months ago

jaydorsey commented 7 months ago

Brief Summary of Changes

Cloudinary has support for contextual metadata but it doesn't appear to be supported as an option during ActiveStorage::Service#url_for_direct_upload.

I want to send additional context to cloudinary when I generate the URL for direct upload, using active storage.

Example:

object.service.url_for_direct_upload(
  object.key,
  ...,
  extra_context: { company: "Rando Co." }
)

Creates this on cloudinary:

image

What does this PR address?

Are tests included?

Reviewer, please note:

Checklist:

I didn't run the full test suite, but tested the file I modified

const-cloudinary commented 6 months ago

@jaydorsey thank you for contribution!

Regarding the first bullet: extra_context is a bit redundant and hard to discover for users. It would be much better to just use context with a reverse_merge as you wrote. I don't see any danger in that.

Regarding storing structured and contextual metadata on both Cloudinary and Rails would lead to syncing issues (when it is updated on either side and that leads us to an unknown/invalid state). It's up to customer to implement the desired logic.

If I miss something please let me know.

Thanks!

jaydorsey commented 6 months ago

@jaydorsey thank you for contribution!

Regarding the first bullet: extra_context is a bit redundant and hard to discover for users. It would be much better to just use context with a reverse_merge as you wrote. I don't see any danger in that.

I agree, this does sound better.

Regarding storing structured and contextual metadata on both Cloudinary and Rails would lead to syncing issues (when it is updated on either side and that leads us to an unknown/invalid state). It's up to customer to implement the desired logic.

This also makes sense.

I updated my PR to try and reflect these changes. I also setup my system to be able to run the full test suite and the entire suite is green

const-cloudinary commented 6 months ago

@jaydorsey thank you for contribution!