![](/style/images/good.png)
![](/style/images/bad.png)
[ActiveStorage] Custom Metadata by joshuamsager · Pull Request #43294 · rails/ra...
source link: https://github.com/rails/rails/pull/43294
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Conversation
Summary
Enable instances of ActiveRecord to set metadata on an object.
Many cloud storage providers allow setting metadata on objects in storage. This change leverages the existing metadata
column on active_storage_blobs
to save custom metadata.
For example, custom metadata is saved like so in the DB:
{ "analyzed": true, "width": 200, "height": 200, "custom": { "optimized": true } }
Nesting "custom"
was done intentionally in order to prevent metadata set through rails' analyzer from making it's way to remote storage metadata, without needing to maintain a list of keys in code that the rails' analyzer sets (:width
and :height
for images, and :duration
, :angle
, :display_aspect_ratio
for video/audio).
Notes:
- Setting metadata via direct uploads will require bucket CORS to be updated to include the metadata keys. IE) An app that sets
optimized=true
, would need to add the responseHeader:X-Goog-Meta-Optimized
to their bucket's CORS policy:
[ { "origin": ["MY_ORIGIN"], "method": ["PUT"], "responseHeader": ["Origin", "Content-Type", "Content-MD5", "Content-Disposition", "X-Goog-Meta-Optimized"], "maxAgeSeconds": 3600 } ]
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK