Hi there! Does anyone know a workaround on how to organize media files by subfolders?
I want to create an admin panel for a blog where authors will work on writing articles. Each article may have at least 5-10 pictures. If all of them are uploaded to a media folder without sorting by subfolders, I'll get a mess...
Thanks in advance!
Here is a way to prefix the filename (not sure if folders are supported)
// Field
{
name: 'original',
label: 'Original filename',
type: 'text',
admin: { hidden: true },
},
// Hook
beforeOperation: [
async ({ operation, args }) => {
if (operation === 'create') {
// Save original filename
const original = args.req.files.file.name || 'example.jpg'
args.data.original = original
// Add filename prefix
args.req.files.file.name = new Date().toJSON().slice(0, 10) + '-' + original
}
},
],
Hey @mihanc - you could also organize your media by adding a tag field or similar, then you can filter by this tag in your collection view.
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.