A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
Hello,
When looking at fileCreate https://shopify.dev/api/admin-graphql/2021-10/mutations/filecreate
The description says: "Creates file assets using an external URL or for files that were previously uploaded using the stagedUploadsCreate mutation. These files are added to the Files page in Shopify admin."
So I'm running stagedUploadsCreate and getting back resourceUrl, url, parameters
The resourceUrl looks like https://shopify.s3.amazonaws.com/tmp/58760069297/products/e3eac73c-64bd-4724-a787-7c2da87e3be0/my-te...
Obviously, this is not this resourceUrl that I need to use with fileCreate since no file data have been sent. it's basically an empty shell at this point.
So I attempt to upload the file using the code sample provided by Shopify https://www.shopify.com/partners/blog/upload-files-graphql-react
const [{ url, parameters }] = data.stagedUploadsCreate.stagedTargets
const formData = new FormData()
parameters.forEach(({name, value}) => {
formData.append(name, value)
})
formData.append('file', file)
const response = await fetch(url, {
method: 'POST',
body: formData
})
I'm getting the status code 201 and status message "Created".
So now I call the fileCreate endpoint with originalSource set to https://shopify.s3.amazonaws.com/tmp/58760069297/products/e3eac73c-64bd-4724-a787-7c2da87e3be0/my-te...
The mutation result is successful but the image hasn't been uploaded:
{
alt: 'TEST',
createdAt: '2021-11-17T22:54:50Z',
fileStatus: 'UPLOADED',
preview: { image: null, status: 'UPLOADED' },
fileErrors: []
}
What I am doing wrong? Do I need to upload the file to an S3 bucket before in order to get a correct url ?
I'd like to use Shopify only for file storage and would like to avoid a temporary solution in between. I know I could also upload the file to the assets folder of a theme but this is not what I want either.
Thanks!
I'm having same issue, have you solved this yet?