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.
- 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?
- 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