I would like to specify a prefix to files when they are being directly uploaded by a user.
This has been mentioned a handful of times rails/rails/issues/44376 and ROR Discussion - activestorage-and-direct-uploading/79832
In my use case these direct uploads are not the primary / preferred path to acquire information. In the preferred path I’m pulling records and storing them with a prefix that makes a tiny bit of sense to a human and I’d prefer to maintain that structure with direct uploads.
I’m thinking the change could look something like:
- Allow a
prefix
to be specified in the DirectUpload constructor - Pass the
prefix
through to the BlobRecord constructor and attributes - Add
prefix
to the permitted blob args in the DirectUpload controller - Add
prefix
to the args in ActiveStorage::Blob.create_before_direct_upload
At this point something would need to be done with the Key attribute in ActiveStorage::Blob as that is currently has_secure_token :key, length: MINIMUM_TOKEN_LENGTH
Perhaps a before_create
that joins a prefix if provided.
I haven’t tried implementing this as I wanted to see if there is a general appetite for this change as I hate for a PR to languish or get rejected because I’ve missed something.
Any interest?