[Proposal] ActiveStorage - Allow a prefix to be supplied with a direct upload

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:

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?

I’m looking for this as I’m trying to migrate from Shrine and my files are already uploaded in a prefixed location.