Resumable Upload gets interrumpted after few GB

允我心安 提交于 2020-01-15 15:35:27

问题


I have a function in php to upload several files through a stand alone script, the first ones upload fine but the last one that's 16GB around 20 minutes it gets interrumpted for no reason and the upload stops. The auth is already handled, so I don't know what may be causing this issue. Here's the code and the error that it outputs:

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

}

Error:

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:


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

The problem is in the Stream library, inside the IO folder. "As a temporary workaround, try commenting out the following clause from IO/Stream.php at line 107:"

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

    $url = self::ZLIB . $url;

}

EDIT: Still didn't work, trying with the MediaFileUpload hotfix of doing the following code in lines 240~ish:

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


来源:https://stackoverflow.com/questions/30676478/resumable-upload-gets-interrumpted-after-few-gb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!