Organize media files by subfolders

default discord avatar
8 months ago

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!

  • default discord avatar
    8 months ago

    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 = || 'example.jpg'
 = original
          // Add filename prefix
 = new Date().toJSON().slice(0, 10) + '-' + original
  • discord user avatar
    Payload Team
    7 months ago

    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.

Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!


Connect with the Payload Community on Discord



Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.