When using ActiveStorage, and calling url_for_direct_upload, I would like the ability to include contextual metadata when I generate my URLS
Explain your use case
Our frontend is handling the upload of the image blob
Our backend is using active storage and url_for_direct_upload to generate a URL which is used to upload the blob
We have additional context metadata that we want the backend to send when the URL is created, rather than via a separate update API call. This is generally "business rule" data that the backend should control/set. Example: Annotating the unique identifier of a person or system that uploaded an asset
Describe the problem you’re trying to solve
An example call from a Ruby class:
class User
has_one_attached :profile_photo
end
u = User.first
blob = ActiveStorage::Blob.create_before_direct_upload!(
key:, filename:, byte_size:, checksum:,
content_type:, metadata:, service_name: :cloudinary
)
blob.service.url_for_direct_upload(
blob.key,
expires_in: ActiveStorage.service_urls_expire_in,
content_type: blob.content_type,
content_length: blob.byte_size,
checksum: blob.checksum,
access_mode: 'authenticated',
# This is the data I want to send to cloudinary
context: { caption:, alt:, user_id: u.id }
)
The cloudinary service hard-codes the context sent via url_for_direct_uploadhere
options[:context] = {active_storage_key: key}
What cloudinary does with this data is shown in this screenshots from the cloudinary UI.
active_storage_key is what cloudinary sent. company is something I sent using my patched gem, as a demo that you can just send extra key/value pairs and the API itself supports it
I have some concerns about the naming convention I chose that are annotated in the PR as well:
Whether sending context with the upload url request like this is a good behavior
Whether there would be a conflict (key naming?) if rails 7 custom metadata support was added, or if there is a cloudinary strategy/interest to support that feature
Whether this would conflict with supporting both contextual metadata & structured metadata
Hi @jaydorsey,
Thanks for the PR, I've forwarded your suggestion to our development team for consideration, and they will respond soon.
Warm regards,
Tamara
Feature request for Cloudinary Ruby SDK
When using ActiveStorage, and calling
url_for_direct_upload
, I would like the ability to include contextual metadata when I generate my URLSExplain your use case
url_for_direct_upload
to generate a URL which is used to upload the blobDescribe the problem you’re trying to solve
An example call from a Ruby class:
The cloudinary service hard-codes the context sent via
url_for_direct_upload
hereWhat cloudinary does with this data is shown in this screenshots from the cloudinary UI.
Do you have a proposed solution?
I have a PR here
I have some concerns about the naming convention I chose that are annotated in the PR as well:
context
with the upload url request like this is a good behavior