FROM CACHE - en_header

How can I uniquely identify a file I just uploaded?

Lull
Excursionist
34 1 6

Hi,

I use the graphql mutation fileCreate to upload files. The returned data is a list of files, and a single file has the following parameters: alt, createdAt, fileErrors, fileStatus and preview. Preview contains an "image" field, but this is null, which means there is no unique parameter I can use later on.

I need to be able to lookup the file I just uploaded at a later point to determine whether it still exists, but there is no unique identifier. I can query files on filename, but that is not unique enough, as you can e.g. upload "cat.png" several times, and then Shopify adds something to the name to make it unique. If only this new filename was returned in the fileCreate response.

As a hack I can set the file name to an id that is unique on my end, but I think there should be a less hackish solution.

Any suggestions for how I can determine whether a file I previously uploaded still exists?


Thanks,

-Louise

Replies 2 (2)
Michael_CLift
Shopify Partner
10 0 13

Hi Louise,

 

i am curious to know if you did find a better solution other than generating a unique file name?

 

The current API design seems very limited.  Did anyone else find another solution to uniquely identify a newly uploaded file?

 

Best regards 

Michael

 

 

 

Michael_CLift
Shopify Partner
10 0 13

I've found the following solution to work for finding the uploaded file:

 

fileCreate:

mutation fileCreate($files: [FileCreateInput!]!) {
  fileCreate(files: $files) {
    files {
      __typename
      createdAt
      fileStatus
      fileErrors {
        code
        message
        details
      }
      ... on MediaImage {
        id
      }
    }
    userErrors {
      field
      message
    }
  }
}

Important to fetch the ID on the MediaImage

 

Then fetching the MediaImage via ID to get the originalSrc URL:

query($id: ID!) {
  node(id: $id) {
    __typename
    ... on MediaImage {
      id
      status
      fileStatus
      fileErrors {
        code
        details
        message
      }
      mediaErrors {
        code
        details
        message
      }
      image {
        originalSrc
        transformedSrc(maxWidth: 400)
      }
    }
  }
}