#S3 & Hashing Filenames

7 messages · Page 1 of 1 (latest)

worthy marsh
#

I am currently hashing filenames using a beforeOperation hook in order to rewrite the filename during upload. This ensures files stored in S3 don't retain their original filename, and their URLs reflect this.

However one side effect is the labelling of the file within Payload CMS. As part of the hook, I capture the original filename and store it in a field on the document, and can use this as the title in the collection's List view, but the Upload field component always displays the filename.

Does anyone have any suggestions for how to have hashed filenames, but also ensure a good editing experience? Would be great if the Upload field had an admin.filenameField that let you specify a field to override, but maybe there's a simpler solution I'm not seeing.

Thanks!

scenic houndBOT
radiant grove
#

One thing that you can do is having a title field in your collection and then use that for the useAsTitle prop. This will show the title of the image in the relationship fields:

fields: [
    {
      name: 'title',
      type: 'text',
      admin: {
        description: 'For internal use only',
      },
      required: true,
    },
  ],
  admin: {
    useAsTitle: 'title',
    defaultColumns: ['filename', 'title', 'updatedAt', 'createdAt'],
  },
worthy marsh
#

Thanks, I was actually already doing that but the upload field still displays the filename field

inner raven
worthy marsh
#

yeah good call, i thought about doing that but wanted to ask here first in case there was something even easier

#

will give that a shot instead!