Join us for an upcoming Shopify Partner webinar on February 27, 2024. Discover the latest Checkout Extensibility features, and deep dive on improvements to Shopify Functions and Web Pixels. Register now for either the 10am EST or 2pm EST sessions.

Shopify Graphql Error on upload pdf file on google

antonioreale
Shopify Partner
17 1 2

Hello, I am trying to upload a file with graphql stagedUploadsCreate.

The graphql request is fine, I am getting all the parameters, but when I post on stage url I am getting from google this error: 

<?xml version='1.0' encoding='UTF-8'?><Error><Code>InvalidArgument</Code><Message>Invalid argument.</Message><Details>Cannot create buckets using a POST.</Details></Error>

I am passing the resulting parameters as pairs key, value.

 

What is the right way to upload a file document pdf?

 

Replies 3 (3)

JermyAublc
Shopify Partner
3 0 0

Hello, 

 

I'm facing the same issue ! (is it working with curl command but it's not working with an PHP call (HTTP facade from Laravel))

Did you find the solution ?

 

Thank you

 

Thank you

flyingL123
Visitor
2 0 0

After lots of trial and error I was able to get this working properly. The trick was to use the 'attach' method on the HTTP facade. 

 

$data = [];

foreach (Arr::get($targetResponse, 'data.stagedUploadsCreate.stagedTargets.0.parameters') as $param) {
	$data[$param['name']] = $param['value'];
}

$uploadResponse = Http::attach('file', file_get_contents($localFileName))
	->post(
		Arr::get($targetResponse, 'data.stagedUploadsCreate.stagedTargets.0.url'),
		$data
	);

 

For me, this results in a successful file upload.

flyingL123
Visitor
2 0 0

After lots of trial and error I was able to get this working properly. The trick was to use the 'attach' method on the HTTP facade. 

 

 

 

$data = [];

foreach (Arr::get($targetResponse, 'data.stagedUploadsCreate.stagedTargets.0.parameters') as $param) {
	$data[$param['name']] = $param['value'];
}

$uploadResponse = Http::attach('file', file_get_contents($localFileName))
	->post(
		Arr::get($targetResponse, 'data.stagedUploadsCreate.stagedTargets.0.url'),
		$data
	);

 

 

 

For me, this results in a successful file upload.