Not getting an url in return when using the fileCreate mutation

Hi all!

I’m using the fileCreate mutation to upload an image, after that I’m expected to get an URL back for the image, but it returns null every time. Is this normal or am I misunderstanding something?

The staging and upload process works fine, its just the return that’s not what I’m expecting.

const response = await admin.graphql(
    `
    mutation fileCreate($files: [FileCreateInput!]!) {
      fileCreate(files: $files) {
        files {
          alt   
          ... on MediaImage {
            id
            mediaContentType
            mimeType
            status
            preview {
              image {
                url
              }
            }  
            image {
              src
              url(transform: {})
              id
            }
          }
          ... on Video {
            id
            filename
            preview {
              image {
                url
              }
            }
          }
        }
      }
    }`,
    {
      variables: {
        files: {
          contentType: type,
          originalSource: resourceUrl,
        },
      },
    }
  );

preview also has a status, what is its value?

The preview image returns null until status is READY .

I’m getting { status: ‘UPLOADED’ } for that in the initial response. Right now I’ve solved this with a delay, and then I go and fetch the image again. But it makes it feel slow.

Your approach makes sense. There is some background work happening. The file created and acknowledged, but you’ll have to poll for that information to know when it is ready. The create doesn’t wait for all background work to be completed which could make it feel slow for other users.

1 Like