How to get the Filename of an Object of Type File to Preview it in a List View

2 replies
Last updated: May 26, 2021
how can you get the filename of an object of type file to preview it in a list view? it is easy to get the nested fields to preview content, but i have no idea how to access the objects data istself

const pdf: IObjectType = {
  name: 'pdf',
  title: 'PDF',
  type: 'file',
  description: 'Upload PDF files.',
  fields: [
    {
      name: 'title',
      title: 'Descriptive Name for PDF in Download Card',
      type: 'string',
      validation: (Rule: IRuleType): IRuleType => Rule.required(),
    },
  ],
  …,
  preview: {
    …
  }
}

May 26, 2021, 1:59 PM
Actually, I think I get you now. By setting that title in
fields
on
file
, it overrides the default preview (which appears to be
originalFilename
).
In your
file
preview, can you try:

select: {
  title: 'asset.originalFilename'
}
May 26, 2021, 2:38 PM
ahh, cool… that works, thanks alot
May 26, 2021, 4:11 PM

Sanity.io – build remarkable experiences at scale

Sanity is a customizable solution that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Categorized in