"Content-length smaller than lower bound on range" error when trying to upload video with GraphQL

Solved
Matthias7
Excursionist
30 3 3

Hi all,

 

So I managed to crack how to upload images to Shopify using this: https://shopify.dev/apps/online-store/media/products

I am now trying to upload videos, using pretty much the same workflow, and its going grand until I reach the part where I am to upload my file to the Amazon/Google bucket to then get a URL to post to createProductMedia().

I receive:

stdClass Object ( [Code] => EntityTooSmall [Message] => Your proposed upload is smaller than the minimum object size specified in your Policy Document. [Details] => Content-length smaller than lower bound on range )

as an error message.

 

I have tried with different sized videos, over 5mb and under 5mb, and in StagedUploadsCreate adjusted the "fileSize" parameter to account for which video I am trying to upload.

Has anyone encountered this problem before? 


I will gladly post more code if this post receives any traction, but for now am just wondering if anyone has encountered this error before, in the meantime I will keep trying 😉 

Cheers,

Matthias

Accepted Solution (1)
ShopifyDevSup
Shopify Staff
Shopify Staff
1200 190 418

This is an accepted solution.

Hello again @Matthias7 👋


Below is a sample curl request that may be helpful to upload the video. When the upload is successful, there generally isn't a response body other than the 204 code. Keep in mind, we'll want to arrange the file to be last in the form data. 

curl -L -X POST {StagedMediaUploadTarget.url GOES HERE} \
-F 'GoogleAccessId={StagedMediaUploadTarget.parameters CONTAINS THIS}' \
-F 'key={StagedMediaUploadTarget.parameters CONTAINS THIS}' \
-F 'policy={StagedMediaUploadTarget.parameters CONTAINS THIS}' \
-F 'signature={StagedMediaUploadTarget.parameters CONTAINS THIS}' \
-F 'file=@{RELATIVE PATH DIR TO VIDEO FILE}'


To streamline the process, you can store the response from `stagedUploadsCreate` mutation then build the upload request by iterating over the `parameters` list. The `url` field will be needed in the upload step, and the `resourceUrl` will be consumed to create the video resource object. 

 

Hope that helps!

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

View solution in original post

Replies 3 (3)
Matthias7
Excursionist
30 3 3

Ok so I found what causes this error based on another Forum post: 

https://community.shopify.com/c/shopify-discussions/cannot-upload-video-object-to-the-shopify-via-ap...
there it states that an incorrect parameter is being sent as the file e.g. a string being sent rather than the file itself.

 

Since I am using PHP and CURL I have tried the following to remedy this:  

1. To use "new \CURLFile()" (like I do when successfully uploading Images) - I get no response from API, error or otherwise

2. To use "file_get_contents()" - I get no response from API, error or otherwise

Open to suggestions 😄 

Cheers,
Matthias 

ShopifyDevSup
Shopify Staff
Shopify Staff
1200 190 418

This is an accepted solution.

Hello again @Matthias7 👋


Below is a sample curl request that may be helpful to upload the video. When the upload is successful, there generally isn't a response body other than the 204 code. Keep in mind, we'll want to arrange the file to be last in the form data. 

curl -L -X POST {StagedMediaUploadTarget.url GOES HERE} \
-F 'GoogleAccessId={StagedMediaUploadTarget.parameters CONTAINS THIS}' \
-F 'key={StagedMediaUploadTarget.parameters CONTAINS THIS}' \
-F 'policy={StagedMediaUploadTarget.parameters CONTAINS THIS}' \
-F 'signature={StagedMediaUploadTarget.parameters CONTAINS THIS}' \
-F 'file=@{RELATIVE PATH DIR TO VIDEO FILE}'


To streamline the process, you can store the response from `stagedUploadsCreate` mutation then build the upload request by iterating over the `parameters` list. The `url` field will be needed in the upload step, and the `resourceUrl` will be consumed to create the video resource object. 

 

Hope that helps!

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

Matthias7
Excursionist
30 3 3

A true hero! 


Thank you for your time.


I was tunnel visioning and following too closely the `BulkOperation` procedure.
I was expecting to:
1. receive a reply from the CURL request you posted above
2. then use that reply in the `originalSource` field

Using the `resourceUrl` in `
productCreateMedia` from `stagedUploadsCreate` uploaded the file like a charm. 🙂

 

Cheers,
Matthias