Can't get filename property of a file from Admin API

Hello,

I am creating a bunch of images using fileCreate mutation of GraphQL Admin API, giving them unique names by setting filename property defined in FileCreateInput type. That works fine; the files I created appear on the Content/File page with the names I gave them; I also can use these names in searches. However, I cannot figure out how to get the “filename” property those files though the Admin API. It is not defined on the File type, and I could not find it on any of the derived types. Is this possible?

Thanks!

I’m having the same problem, resorting to getting it from the url … not a good experience.

The admin console does get the filename from a graphql query - it’s a field called “displayName” on the file, but it doesn’t seem to be available in “normal” graphql (together with other useful data such as connectedResourceCount and connectedResourceInfos:

Any ideas how can this be useful to actually get the info?

Hi,

This is Richard at PageFly - Shopify Advanced Page Builder app.

You’ve hit upon a known limitation of the Shopify Admin API’s File object. While you can set the filename during creation, it’s not directly exposed as a field you can query afterward.

Here’s a breakdown of the situation and potential workarounds:

Why the filename is Not Directly Queryable:

  • Internal Naming vs. User-Facing Labels: Shopify’s internal file management might use the filename for storage and identification, but it treats it more as a metadata property than a primary field like id or url.
  • Focus on url and alt: The API primarily focuses on providing access to the file’s url (for accessing the actual file) and alt (for alternative text).
  • Potential for Future Updates: Shopify’s API is subject to change, so this behavior could be altered in future versions.

Workarounds and Alternatives:

  1. Maintain a Local Mapping:

    • The most reliable approach is to keep a local database or mapping of the filename you assigned during creation and the corresponding file.id or url.
    • When you create a file using fileCreate, store the filename and the returned file.id in your system.
    • This allows you to look up the filename based on the file.id or url when needed.
    • This is the most reliable way to ensure you have access to the filenames.
  2. Use alt for Filename-like Information (If Applicable):

    • If your use case allows, you could store a version of the filename in the alt field during file creation.
    • You can then retrieve the alt field using the API.
    • However, this approach is limited by the intended purpose of the alt field (accessibility) and may not be suitable for all situations.
  3. Consider Using Metafields (Less Ideal):

    • You could potentially use metafields to store the filename associated with a File.
    • However, this adds complexity and may not be the most efficient solution.
    • Metafields are also designed for different purposes.
  4. Feature Request to Shopify:

    • Submit a feature request to Shopify’s developer support or through their forums.
    • Explain your use case and why access to the filename is essential for your application.
    • While there’s no guarantee of implementation, it helps Shopify understand developer needs.

Hoping my solution helps you solve your problem.

Best regards,

Richard | PageFly