Steve Scott
Steve Scott

Reputation: 1522

Curl upload to Google/Shopify fails with 400 error and 'Malformed multipart body'

I am trying to upload a glb file to Shopify using Google through cURL. I generate a placeholder url on Google through GraphQL and then I use curl to upload to this temp URL. When I link the image to Shopify using another GraphQL API post I Shopify says "Some of your media failed to upload"

I took some headers from this answer to enable multipart uploading of this file: Getting "Malformed multipart body" when trying to upload video to YouTube

Here is the Shopify instructions which are mostly for video: https://shopify.dev/tutorials/manage-product-media-with-admin-api

I get a 400 error, but it shows that everything uploaded, but the upload time is one second for a 1.7 MB file. I guess my internet is fast, but how did everything upload if there was a 400 error?

I noticed the Content-Length value is larger than the X-Upload-Content-Length value (measured on the file itself using Python getsize()), which is different from the size of the file listed on the file system and in the upload display.

This is my curl string (in python):

    bashCommand = '''curl -v -H "Accept:application/json" -H "Content-Type:multipart/form-data" -H "x-upload-content-type:application/octet-stream" -H "X-Upload-Content-Length:{}" -F "GoogleAccessID={}" -F "key={}" -F "policy={}" -F "signature={}" -F file=@{}  {}'''.format(filesize, google_access_id, key, policy, signature, glb_path, url)

This is the verbose output:

> Host: storage.googleapis.com
> User-Agent: curl/7.55.1
> Accept: */*
> "Accept:application/json"
> "Content-Type:multipart/form-data"
> "x-upload-content-type:application/octet-stream"
> "X-Upload-Content-Length:1800252"
> Content-Length: 1801555
> Expect: 100-continue
> Content-Type: multipart/form-data; boundary=------------------------086d33ba0b272238
>
* schannel: client wants to read 102400 bytes
* schannel: encdata_buffer resized 103424
* schannel: encrypted data buffer: offset 0 length 103424
* schannel: encrypted data got 54
* schannel: encrypted data buffer: offset 54 length 103424
* schannel: decrypted data length: 25
* schannel: decrypted data added: 25
* schannel: decrypted data cached: offset 25 length 102400
* schannel: encrypted data buffer: offset 0 length 103424
* schannel: decrypted data buffer: offset 25 length 102400
* schannel: schannel_recv cleanup
* schannel: decrypted data returned 25
* schannel: decrypted data buffer: offset 0 length 102400
< HTTP/1.1 100 Continue
} [1255 bytes data]
 21 1759k    0     0   21  385k      0   385k  0:00:04 --:--:--  0:00:04 1027k* schannel: client wants to read 102400 bytes
* schannel: encrypted data buffer: offset 0 length 103424
* schannel: encrypted data got 502
* schannel: encrypted data buffer: offset 502 length 103424
* schannel: decrypted data length: 473
* schannel: decrypted data added: 473
* schannel: decrypted data cached: offset 473 length 102400
* schannel: encrypted data buffer: offset 0 length 103424
* schannel: decrypted data buffer: offset 473 length 102400
* schannel: schannel_recv cleanup
* schannel: decrypted data returned 473
* schannel: decrypted data buffer: offset 0 length 102400
< HTTP/1.1 400 Bad Request
< Content-Type: text/plain; charset=utf-8
< X-GUploader-UploadID: ABg5-UzLfsxk4ALL0C4Fewm8gTDel_583XI_OahsahS8HO25JZ6SXzSVudsJvfsA8YOguKoE7XXafAc0UXxH16jBpNsUszb5yg
< Content-Length: 25
< Date: Sat, 20 Mar 2021 19:33:55 GMT
< Server: UploadServer
< Alt-Svc: h3-29=":443"; ma=2592000,h3-T051=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"
* HTTP error before end of send, stop sending
<
{ [25 bytes data]
100 1759k  100    25  100 1759k     25  1759k  0:00:01 --:--:--  0:00:01 2048k
* Closing connection 0
* schannel: shutting down SSL/TLS connection with storage.googleapis.com port 443
* schannel: clear security context handle


 curl output: b'Malformed multipart body.'


 error: None

Any insight? There are a lot of technologies at work here.

Upvotes: 0

Views: 460

Answers (1)

Steve Scott
Steve Scott

Reputation: 1522

I looked at the headers and noticed that my headers had quotes and the actual headers had no quotes. Removed the quotes from the curl string and it works now.

Upvotes: 1

Related Questions