Discussing APIs and development related to customers, discounts, and order management.
Recently the fileCreate GraphQL endpoint was released. It allows to upload files on the store that will end up under "Settings" > "Files".
My goal is to get the file url in order to use it in a product description once the upload is done.
The only way to get a file url is through the file.preview.image attribute on the file, nonetheless when I insert the file, the file.preview.image returned is null.
My GraphQL body is the following:
query = f""" mutation {{
fileCreate(files: [{{
originalSource: "{dropbox_url}"
contentType: IMAGE
alt: "PLOP"
}}]) {{
files {{
alt
createdAt
fileStatus
preview {{
status
image {{
altText
height
id
originalSrc
transformedSrc
width
}}
}}
}}
userErrors
{{
code
field
message
}}
}}
}}
"""
After some time if I read the files from the shop (through GraphQL), then the preview is returned correctly. My guess is that the preview is computed and take some time so the fileCreate returns an empty image at first.
Because the File does not have and id, I cannot simply wait a little bit and retrieve the image url. I would need to loop through all the files and match the file I just inserted with the right file using the created date timestamp (sub optimal).
Is this expected ?
Do you see another way to get the file url ?
Solved! Go to the solution
This is an accepted solution.
I've got it! Run a second query on files and query the filename!
See my answer here:
Unfortunately I don't have the answer for you, but I am experiencing exactly the same issue.
I'm using fileCreate to upload a file, but I can't then get the url I need because image is always null!
This is an accepted solution.
I've got it! Run a second query on files and query the filename!
See my answer here:
Thanks for the workaround, indeed it works.
The issue in my case is that I create the file then read it right away so I have to loop and sleep while waiting for the file to be ready.
I've had to do the same as well! It's pretty annoying and very clunky!
I've got mine wrapped in a do / while loop with a sleep of 10 seconds. It resolves on the third cycle usually.
Not ideal, but it works!