🔮 Sanity Create is here. Writing is reinvented. Try now, no developer setup

Issue with getting the originalFilename of an asset when using the getFileAsset function.

10 replies
Last updated: Nov 11, 2021
Hi, how to get the ‘originalFilename’ of an asset when using https://sanity-io.github.io/asset-utils//index.html#getfileasset .
apiHost: "<https://api.sanity.io>"
apiVersion: "1"
cdnUrl: "<https://xx9fbq46.apicdn.sanity.io/v1>"
dataset: "staging"
gradientMode: false
isDefaultApi: true
isPromiseAPI: true
originalFilename: true
projectId: "xxxxxxx"
url: "<https://xx9fbq46.api.sanity.io/v1>"
useCdn: false
useProjectHostname: true
useVanityName: true
I’m passing ‘useVanityName: true’ in the options (above), along with the Project ID and dataset, however no originalFilename in the result. Thanks.
Nov 10, 2021, 11:10 AM
Hi User
Here’s the asset:

asset: {_ref: 'file-893ae787544e3999c424bd5082924052795efe8d-pdf', _type: 'reference'}
itemMetaData: {_type: 'itemMetaData', caption: 'First factory design in Den Bosch'}
_key: "f04292f7c88b"
_type: "fileItem"

const assetData = getFileAsset(asset._ref, client.config())
The response from getFileAsset():

assetId: "893ae787544e3999c424bd5082924052795efe8d"
extension: "pdf"
metadata: {}
path: "files/xxxxx/staging/893ae787544e3999c424bd5082924052795efe8d.pdf"
url: "<https://cdn.sanity.io/files/xxxxxx/staging/893ae787544e3999c424bd5082924052795efe8d.pdf>"
_id: "file-893ae787544e3999c424bd5082924052795efe8d-pdf"
_type: "sanity.fileAsset"

Nov 10, 2021, 8:04 PM
Expected is originalFilename as documented here?:
Nov 10, 2021, 8:06 PM
Interesting. Is it possible that the original filename isn't set on the asset. For example, if you query it in Vision does it have an original filename property?
Nov 10, 2021, 8:55 PM
*[_type == "project" && _id == "18307598-bda2-420d-9243-396f5e1271de"]{
  "doc": documents[0]{asset->{path,url,_type, extension, originalFilename}}

    "doc": {
      "asset": {
        "_type": "sanity.fileAsset",
        "extension": "pdf",
        "originalFilename": "20160708 Protix.pdf",
        "path": "files/xxxxxx/staging/893ae787544e3999c424bd5082924052795efe8d.pdf",
        "url": "<https://cdn.sanity.io/files/xxxxxxxx/staging/893ae787544e3999c424bd5082924052795efe8d.pdf>"
Nov 10, 2021, 9:39 PM
It’s there via Vision.
Nov 10, 2021, 9:40 PM
This does look like a bug. Do you mind filing an issue in the package's repo? Imll alert the internal team.
Nov 10, 2021, 10:48 PM
Nov 11, 2021, 10:43 AM
Nov 11, 2021, 11:36 AM

Sanity– build remarkable experiences at scale

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

Was this answer helpful?