Focusing on managing products, variants, and collections through the API.
I'm following this tutorial to upload an image to Shopify. After calling the generateStagedUploads mutation, the doc gives me a curl command. I try it and it works. But the curl command is using a local file. I'm working on a Django app. My image file is uploaded by users and it's available via request.FILES['filename']
I have a few questions here.
def uploadImage(stagedTarget, file): parameters = stagedTarget["parameters"] url = stagedTarget["url"] files = { 'file': file, } data = { 'Content-Type': parameters[0]['value'], 'success_action_status': parameters[1]['value'], 'acl': parameters[2]['value'], 'key': parameters[3]['value'], 'x-goog-date': parameters[4]['value'], 'x-goog-credential': parameters[5]['value'], 'x-goog-algorithm': parameters[6]['value'], 'x-goog-signature': parameters[7]['value'], 'policy': parameters[8]['value'], } print(f"{url = }, {data = }") response = requests.post(url, files=files, data=data) print(f"{response.status_code = }") print(f"{response.text = }") response = response.content response = json.loads(response)
But it gives me
response.status_code = 400 web_1 | response.text = "<?xml version='1.0' encoding='UTF-8'?><Error><Code>EntityTooSmall</Code><Message>Your proposed upload is smaller than the minimum object size specified in your Policy Document.</Message><Details>Content-length smaller than lower bound on range</Details></Error>"
I don't know what is going wrong. My file size is 46992. I don't think it's too small? I can upload a similar image with curl
Hey @jam_chan - the error you're seeing is likely a generic error being surfaced by Google - there is no minimum size limit for staged uploads. One thing that could cause the issue is the Content-Type header using an incorrect value. Could you confirm if you're using the "img/[file extension type)" header value there?
Hope this helps - let us know if we can clarify anything further. Generally, we're unable to help with code-level troubleshooting, but I'm happy to dig in as best we can, if needed.
Al | Shopify Developer Support
Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
how you solve this?