Cannot upload an image to Shopify after calling generateStagedUploads

jam_chan
Shopify Partner
856 23 161

 

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.

  1. the curl command is using a local file. Does it suppose that I'm uploading the file in the command line? When the users upload a file in the Shopify app, I don't think I should use curl on the server?
  2. Following 1, I come up with the conclusion that I should use my way to send a POST request with Python. So I'm trying to translate the curl command to python codes.

 

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

 

BYOB - Build Your Own Bundles, SPO - SEO App to research keywords & edit social link preview
Replies 3 (3)
ShopifyDevSup
Shopify Staff
Shopify Staff
1202 190 419

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

jam_chan
Shopify Partner
856 23 161

I've fixed the issue with the help of chatgpt and stackoverflow. Thanks

BYOB - Build Your Own Bundles, SPO - SEO App to research keywords & edit social link preview
Rfynther
Shopify Partner
2 0 1

how you solve this?

Best regards