我正在尝试使用PHP将文件上传到Google云端硬盘。我正在使用多部分类型的上传,因为它是一个大文件(MySQL数据库备份)。这将从shell脚本运行以进行备份。
每当发布一个小文件时,我的代码都会完美运行,并且该文件会上传到Google云端硬盘。但是,每当我尝试上传更大的文件时,我都会收到错误
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()
生成。