Access a community of over 900,000 Shopify Merchants and Partners and engage in meaningful conversations with your peers.
I have been trying to figure out how to upload media for a few days. Now I have gotten uploading videos correctly, with the help of this tutorial - https://shopify.dev/tutorials/manage-product-media-with-admin-api. However, I cannot seem to push images up to Shopify.
1. Under https://shopify.dev/tutorials/manage-product-media-with-admin-api#upload-the-asset, if I were to do a POST request for an image, I am missing the policy attribute to add to my form. I've tried api versions 2020-01 and 2020-07, and the policy isn't returned in either the params of the url or parameters returned by the "stagedUploadsCreate" mutation.
I've also tried excluding the "nonexistent" attributes that are in the documentation (i.e. AWSAccessKeyId, policy, signature) and instead include all the parameters in the url but not in doc (e.g. x-amz-acl, X-Amz-Algorithm, X-Amz-Credential, X-Amz-Signature, etc.). In this case, an InternalError is thrown - "We encountered an internal error. Please try again".
2. For PUT requests, I have not found a way to mimic curl -T or --upload-file (as per example given in documentation) with axios.
Any help is appreciated, thanks.
Edit: I have tried both productCreateMedia (which works for videos) and productAppendImages mutations, and neither worked with images, so I'm assuming something went wrong in the uploading step.
Solved! Go to the solution
This is an accepted solution.
Nevermind, I needed to add "httpMethod" attribute for post requests.
This is an accepted solution.
Nevermind, I needed to add "httpMethod" attribute for post requests.
What ended up working for you.
I'm getting a 403 back from s3. I'm using the parameters returned by stageUploadsCreate which are:
content_type=image/png
acl=private
Should I also be using the parameters that are in the url? I'm seeing these:
x-amz-acl
X-Amz-Algorithm
X-Amz-Credential
X-Amz-Date
X-Amz-Expires
X-Amz-SignedHeaders
X-Amz-Signature
Thanks!
Yep, that works well, thanks for that.
I am now getting ok response after uploading files, so everything should be fine, however I cannot find those assets in admin/settings/files. Anyone knows what's going on?
Ok figured out I need to make a next graphql api call to fileCreate.
The request goes through, response is ok, however when I go to admin/settings/files, I get failed upload....
 
Hey, are you sending the content-type in the headers?
headers={"Content-Type": mimeType}
This code works for me in python:
with open(image, 'rb') as f:
files = {'file': (image, f)}
r = requests.put(target["url"], headers={"Content-Type": mimeType)}, files=files)
the url is in the response of stagedUploadsCreate graphql API targets