Image and file upload via mutation generateStagedUploads problem

MR_DEVELOPERS
Shopify Partner
7 0 5

Hi Community Developers,

I have failed to upload file via Graphql generateStagedUploads. Can someone help?

I followed this tutorial https://shopify.dev/api/examples/product-media. But the response seems not exactly same. In my response I can not find the bucket name, policy and other fields from parameters: []. so I assumed that I can use the "url" in "stagedTargets": [] directly. But I always got an SignatureDoesNotMatch error.

 

<Code>SignatureDoesNotMatch</Code>
<Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message>

 

The did the following steps:


I made a call:

 

mutation generateStagedUploads($input: [StagedUploadInput!]!) {
                      stagedUploadsCreate(input: $input) {
                        stagedTargets {
                          url
                          resourceUrl
                          parameters {
                            name
                            value
                          }
                        }
                        
                      }
                    }
variables = {
                  "input": [
                    {
                      "filename": "blank-logo.png",
                      "mimeType": "image/png",
                      "resource": "IMAGE",
                      "fileSize": str(size)

                    }
                  ]
                }

 

 I got data responsed:

 

{
    "data": {
        "stagedUploadsCreate": {
            "stagedTargets": [
                {
                    "url": "https:\/\/shopify.s3.amazonaws.com\/tmp\/58504741015\/products\/17f18b13-6453-4cd9-a124-5a7c54834df4\/blank-logo.png?x-amz-acl=private\u0026X-Amz-Algorithm=AWS4-HMAC-SHA256\u0026X-Amz-Credential=AKIAJYM555KVYEWGJDKQ%2F20210811%2Fus-east-1%2Fs3%2Faws4_request\u0026X-Amz-Date=20210811T055124Z\u0026X-Amz-Expires=900\u0026X-Amz-SignedHeaders=host\u0026X-Amz-Signature=1e2c67cda90abe7ea6a7c1b2731883f4417badf8139a23807dcb31c129f71e02",
                    "resourceUrl": "https:\/\/shopify.s3.amazonaws.com\/tmp\/58504741015\/products\/17f18b13-6453-4cd9-a124-5a7c54834df4\/blank-logo.png",
                    "parameters": [
                        {
                            "name": "content_type",
                            "value": "image\/png"
                        },
                        {
                            "name": "acl",
                            "value": "private"
                        }
                    ]
                }
            ]
        }
    },
    "extensions": {
        "cost": {
            "requestedQueryCost": 11,
            "actualQueryCost": 11,
            "throttleStatus": {
                "maximumAvailable": 1000.0,
                "currentlyAvailable": 989,
                "restoreRate": 50.0
            }
        }
    }
}

 

and then i make this call in python:

 

headers = {
            'x-amz-acl': 'private',
            'Content-Type': 'image/png'
        }
        with open('blank-logo.png', 'rb') as f:
            response = requests.request("POST", url_aws, headers=headers, data=f)

 

I also tried curl in terminal and postman:

 

curl -v \
  -F "x-amz-acl=private" \
  -F "Mime-Type=image/png" \
  -F "key=tmp/58504741015/products/a1a28122-03b0-42f0-bb58-1626583177f0/blank-logo.png" \
  -F "Filename=blank-logo.png" \
  -F "file=@/Volumes/Development/backend_project/project-blank-integration/blank-logo.png" \
   "https://shopify.s3.amazonaws.com/tmp/58504741015/products/a1a28122-03b0-42f0-bb58-1626583177f0/blank-logo.png?x-amz-acl=private&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAJYM555KVYEWGJDKQ/20210811/us-east-1/s3/aws4_request&X-Amz-Date=20210811T055512Z&X-Amz-Expires=900&X-Amz-SignedHeaders=host&X-Amz-Signature=58391e74775af43ec4585ae078e2178fd19c286d830085f53868e456866f696d"

 

Screen Shot 2021-08-11 at 5.59.33 PM.png

 

Could you please help me with the correct way to using the aws url?

Thank you very much!

Barrick

Replies 3 (3)
fact
Shopify Partner
2 0 0
TudorBNG
Shopify Partner
2 0 0

I have the same issue. Did anyone manage to find a solution?

Matthias7
Excursionist
27 3 3

I just posted a question asking the same thing, does anyone have any enlightenment on the subject?  🙂