似乎无法使用php Guzzle上传大文件

时间:2015-05-19 17:37:03

标签: php curl file-upload guzzle

我在使用Guzzle(5.2.0)

上传大文件时遇到问题

我添加了progress事件监听器并得到了这个输出:

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

它似乎每次卡在1146880字节,挂起然后点击卷曲超时。

以下是我如何格式化guzzle请求:

$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 );

当我切换到使用原始卷曲时,我可以使用' @ filename'上传图片。语法。

有什么想法吗?谢谢!

1 个答案:

答案 0 :(得分:1)

你试过这个吗?

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

我发现这个家伙有类似的问题 - http://alex-panshin.me/blog/file-upload-with-guzzle/

我认为他收到了413(请求太大) - 你得到了什么HTTP错误回复(如果有的话)?

有关详细信息https://craftcms.stackexchange.com/a/2330

,请参阅此处

如果所有其他方法都失败,请尝试捕获使用curl时设置的标题以及使用Guzzle时设置的标题,并确定是否存在差异。