Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/243.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 多部分实体中缺少端点边界_Php_Google Drive Api_Guzzle - Fatal编程技术网

Php 多部分实体中缺少端点边界

Php 多部分实体中缺少端点边界,php,google-drive-api,guzzle,Php,Google Drive Api,Guzzle,我试图上传一个文件到谷歌驱动器使用PHP。我使用多部分上传,因为它是一个大文件(MySQL数据库备份)。出于备份目的,这将从shell脚本运行 无论何时发布一个小文件,我的代码都能正常工作,文件会上传到谷歌硬盘。然而,每当我试图上传一个更大的文件时,就会出现一个错误 HTTP/1.1 400 Bad Request Content-Length: 39 Date: Mon, 06 Oct 2014 12:41:30 GMT Server: UploadServer ("Built on Sep

我试图上传一个文件到谷歌驱动器使用PHP。我使用多部分上传,因为它是一个大文件(MySQL数据库备份)。出于备份目的,这将从shell脚本运行

无论何时发布一个小文件,我的代码都能正常工作,文件会上传到谷歌硬盘。然而,每当我试图上传一个更大的文件时,就会出现一个错误

HTTP/1.1 400 Bad Request
Content-Length: 39
Date: Mon, 06 Oct 2014 12:41:30 GMT
Server: UploadServer ("Built on Sep 24 2014 16:50:43 (1411602643)")
Content-Type: text/html; charset=UTF-8
Alternate-Protocol: 443:quic,p=0.01

Missing end boundary in multipart body
我所发布内容的压缩输出是

--54328df935387
Content-Type: application/json; charset=UTF-8

{"title":"MySQL backup","description":"Backup taken of MySQL database"}

--54328df935387
Content-Type: text/plain

-- MySQL dump 10.13  Distrib 5.5.38, for debian-linux-gnu (x86_64)
**ACTUAL DATA OMITTED**
-- Dump completed on 2014-10-06 23:41:29


--54328df935387--
相关的PHP代码是

$post = $client->createRequest('POST','https://www.googleapis.com/upload/drive/v2/files?uploadType=multipart',['expect'=>false,'body'=>$string]);
$post->setHeader('Authorization','Bearer '.$access_token);
$post->setHeader('Content-Type','multipart/related; boundary="'.$boundary.'"');
$length = strlen(json_encode($metadata))+filesize('mysql_backup.sql');
$post->setHeader('Content-Length',$length);
try {
    $response = $client->send($post);
    echo $response->getBody();
} catch (\GuzzleHttp\Exception\ClientException $e){
    echo $e->getResponse();
}
我只能在发布大于1MB的文件时重现此错误


我正在用Guzzle发出POST请求。边界是由
uniqid()

生成的,可能Guzzle库中存在某种数据限制,导致请求被截断?难道不能让Guzzle处理多部分编码之类的事情吗?类似于
$client->post('http://api/endpoint')->addPostFile('file','./mysql_backup.sql')->send()?Guzzle在添加单个文件时工作。但是,驱动器API需要发出一个多部分请求—一个包含元数据,另一个包含实际文件。Guzzle不支持这一点,因此我必须手动构建请求。它没有回答问题,但我最终使用了运行良好的Google PHP客户端库