When accessing a file in directus, it does happen via the ID of the file object.
When Uploading a file and accessing it in PayLoad, it does so via the clear filename.
i.E. i Upload a file with the name
demo.pdf. I can now access the file via
uploads/demo.pdfinstead, it would be nice if instead it could be just a simple UUID or at least the ID of the object.
I saw that there is a hashing-plugin, which still uses the clear name though.
So, main question: Is there already a way of handling file-access this way or do I need to write a plugin for that?
You could rename the file to a uuid in a
beforeOperation
collection hook. There are some examples here (from one of the links by the bot):
https://payloadcms.com/community-help/github/rename-file-on-upload-not-overwriting-other-uploadsYeah, thats what I though of too. The issue then of course is that the filename gets lost.
In Directus files store they actualy filename and then the "OnDisk" filename, which basicly is the ID of the object in the database and the extension of the original file.
You can then either use /assets/{file_id} to get the raw data (and meta-data in the header derived from the DB-entry, i.E. the original filename)
or items/files/{file_id} to get the data stored in the DB.
With Payload I basicly have to access the data of the item first to get the download-path because the downloadpath is returned via API and not easily understandable.
I suppose, it could be somewhat the other way around. Using a preRead hook and checking if the ID exists and returning the download-link. Hmmm.
Yeah, you could definitely get creative here. You could write the incoming filename to a separate field in the hook, so it could still be stored.
Star
Discord
online
Get dedicated engineering support directly from the Payload team..