Unable to upload large files using php Guzzle

I have problems downloading large files using Guzzle (5.2.0)

I added a listener to the progress events and got this conclusion:

Downloaded 0 of 0 Uploaded 966656 of 1467594 Downloaded 0 of 0 Uploaded 983040 of 1467594 Downloaded 0 of 0 Uploaded 999424 of 1467594 Downloaded 0 of 0 Uploaded 1015808 of 1467594 Downloaded 0 of 0 Uploaded 1032192 of 1467594 Downloaded 0 of 0 Uploaded 1048576 of 1467594 Downloaded 0 of 0 Uploaded 1064960 of 1467594 Downloaded 0 of 0 Uploaded 1081344 of 1467594 Downloaded 0 of 0 Uploaded 1097728 of 1467594 Downloaded 0 of 0 Uploaded 1114112 of 1467594 Downloaded 0 of 0 Uploaded 1130496 of 1467594 Downloaded 0 of 0 Uploaded 1146880 of 1467594 Downloaded 0 of 0 Uploaded 1146880 of 1467594 Downloaded 0 of 0 Uploaded 1146880 of 1467594 Downloaded 0 of 0 Uploaded 1146880 of 1467594 Downloaded 0 of 0 Uploaded 1146880 of 1467594 Downloaded 0 of 0 Uploaded 1146880 of 1467594 Downloaded 0 of 0 Uploaded 1146880 of 1467594 Downloaded 0 of 0 Uploaded 1146880 of 1467594 Downloaded 0 of 0 Uploaded 1146880 of 1467594 Downloaded 0 of 0 Uploaded 1146880 of 1467594 Downloaded 0 of 0 Uploaded 1146880 of 1467594 Downloaded 0 of 0 Uploaded 1146880 of 1467594 Downloaded 0 of 0 Uploaded 1146880 of 1467594 

It seems that each time it gets stuck at 1146880 bytes, freezes, and then hits the curl timeout.

Here's how I format a buzz request:

 $client = new \GuzzleHttp\Client(); $endpoint = 'http://myendpoint.com' $file = new splfileobject( '/path/to/file' ) $options = [ "body" => [ "file" => fopen( $file->getRealPath(), 'r' ) ] ] $client->post( $endpoint, $options ); 

When I switch to using raw curl, I can load the image using the @filename syntax.

Any ideas? thanks!

+7
php curl file-upload guzzle
source share
1 answer

Have you tried this?

 "file" => "@" . $file->getRealPath() 

I found that this guy had similar problems - http://alex-panshin.me/blog/file-upload-with-guzzle/

I think he received 413 (Request Too Large) - What HTTP response to the error (if any) do you get?

See this for more information https://craftcms.stackexchange.com/a/2330

If all else fails, try and grab the headers set when using curl and those set when using Guzzle, and find out if there is a difference.

+1
source share

All Articles