Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't seem to upload large files with php Guzzle

I'm having issues uploading large files using Guzzle ( 5.2.0 )

I added the progress event listener and got this output:

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 appears to get stuck at 1146880 bytes every time, hangs and then hits the curl timeout.

Here's how I'm formatting the guzzle 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'm able to upload the image using the '@filename' syntax.

Any ideas? thank you !

like image 429
mikeklein Avatar asked May 19 '15 17:05

mikeklein


1 Answers

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 was receiving a 413 (Request Too Large) - What HTTP error response (if any) are you getting?

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

If all else fails try and capture the headers set when using curl and those set when using Guzzle and figure out if there's a difference.

like image 82
Carlton Avatar answered Nov 13 '22 01:11

Carlton