What we want to achieve
I want to specify arbitrary metadata when uploading files to S3 or other storage.
For example, “Git revision”, “RequestID”, or “GlobalID of the record associated with the blob at the time of upload”.
This is to be able to track when a record in a ActiveStorage::Blob
has been deleted but the object remains in storage.
How to achieve this in Rails at this time
ActiveStorage::Blob#custom_metadata=
is defined!
However, this method cannot be utilized when uploading files using ActiveStorgae in a straightforward manner.
I am applying this patch to ActiveStorage::Blob
.
Proposal
How about a configuration item that allows custom_metadata
to be specified more easily?
For example, it looks like this.
# config/application.rb
config.active_storage.custom_metadata_proc = lambda do
{
revision: ENV["REVISION"],
request_id: Current.request_id
}
end
ActiveStorage::Blob#custom_metadata
is a very nice feature, but I feel it is not used very often, perhaps because it is difficult to use.
If this could be accomplished without patching, that would be great.
off topic
The record
that triggered the file upload is passed as an argument to the blob method, but is discarded.
It would be great if it could be treated as an attribute of ActiveStorage::Blob
, so that it can be used in combination with this Topic.
(Yes, like my patch.