几英寸

时间:2015-06-05 22:03:21

标签: php google-drive-api google-api-php-client

我在php中有一个函数可以通过一个独立的脚本上传几个文件,第一个上传很好但是最后一个16GB大约20分钟就会无缘无故地上传,上传就停止了。身份验证已经处理完毕,因此我不知道可能导致此问题的原因。这是输出的代码和错误:

function insertFile($client,$service,$filePath,$name,$fId){

    $file = new Google_Service_Drive_DriveFile();
    $file->title = $name;       
    $parent = new Google_Service_Drive_ParentReference();
    $parent->setId($fId);
    $file->setParents(array($parent));

    $chunkSizeBytes = 1 * 1024 * 1024;


    $client->setDefer(true);
    $request = $service->files->insert(
        $file,
        array(
            'uploadType'=> 'resumable'
        )
    );

    $finfo= finfo_open(FILEINFO_MIME_TYPE);




    $media = new Google_Http_MediaFileUpload(
          $client,
          $request,
          finfo_file($finfo, $filePath),
          null,
          true,
          $chunkSizeBytes
    );


    $media->setFileSize(filesize($filePath));
    $status = false;
    $handle = fopen($filePath, "rb");
    while (!$status && !feof($handle)) {
        $chunk = fread($handle, $chunkSizeBytes);
        $status = $media->nextChunk($chunk);
    }



    $result = false;
    if($status != false) {
        $result = $status;                          

    }

    fclose($handle);

    $client->setDefer(false);

}

错误:

PHP Fatal error:  Uncaught exception 'Google_IO_Exception' with message 'HTTP Error: Unape=resumable&upload_id=AEnB2UoRrzX46hJ02lIDkCJi03MFbE2KVP2LDCBOgnuiclONk3sBvSctZxW3NxsWt /libs/google-api-php-client/src/Google/IO/Stream.php
Stack trace:
#0 /libs/google-api-php-client/src/Google/IO/Abstract
#1 /libs/google-api-php-client/src/Google/Http/MediaF
#2 /root/name.php(199): Google_Http_MediaFileUpload->nextChunk(
#3 /root/name.php(102): insertFile(Object(Google_Client), /libs/google-api-php-client/src/Google/IO/Stream.php on l

1 个答案:

答案 0 :(得分:0)

根据:https://gae-php-tips.appspot.com/2013/12/23/getting-started-with-the-cloud-datastore-on-php-app-engine/

问题出在IO文件夹内的Stream库中。 "作为临时解决方法,请尝试在第107行的IO / Stream.php中注释掉以下子句:"

if (!$this->client->getClassConfig("Google_Http_Request", "disable_gzip")) {

    $url = self::ZLIB . $url;

}

编辑:仍然没有用,尝试使用MediaFileUpload修补程序在第240行中执行以下代码:ish:

 private function transformToUploadUrl()
  {
    $base = 'https://www.googleapis.com';   //Hardcoded, cambiar si 
    $this->request->setBaseComponent($base . '/upload');
  }