Issue with getting the originalFilename of an asset when using the getFileAsset function.
10 replies
Last updated: Nov 11, 2021
R
Hi, how to get the ‘originalFilename’ of an asset when using https://sanity-io.github.io/asset-utils//index.html#getfileasset .
I’m passing ‘useVanityName: true’ in the options (above), along with the Project ID and dataset, however no originalFilename in the result. Thanks.
{ 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 }
Nov 10, 2021, 11:10 AM
R
Hi User
Here’s the asset:
The response from getFileAsset():
Thanks.
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())
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"
Thanks.
Nov 10, 2021, 8:04 PM
R
Expected is originalFilename as documented here?:
Nov 10, 2021, 8:06 PM
R
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
R
*[_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
R
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
R
Nov 11, 2021, 10:43 AM
R
Thanks!
Nov 11, 2021, 10:43 AM
R
This is resolved, see: https://github.com/sanity-io/asset-utils/issues/4
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.