几GB后,可恢复的上传会被中止 [英] Resumable Upload gets interrumpted after few GB

查看:140
本文介绍了几GB后,可恢复的上传会被中止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个php函数来通过一个独立的脚本上传几个文件,第一个上传正常,但是最后一个16GB左右,大约20分钟,它无缘无故地被中止,上传停止。 auth已经处理完毕,所以我不知道可能是什么原因导致了这个问题。下面是代码和它输出的错误:

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

$ b

错误:

  PHP致命错误:未收到异常'Google_IO_Exception',并显示'HTTP错误:Unape =可恢复& upload_id = AEnB2UoRrzX46hJ02lIDkCJi03MFbE2KVP2LDCBOgnuiclONk3sBvSctZxW3NxsWt / libs / google-api-php-client / src / Google /IO/Stream.php 
堆栈跟踪:
#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 (对象(Google_Client),/libs/google-api-php-client/src/Google/IO/Stream.php on l


解决方案

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



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

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

$ url = self :: ZLIB。 $网址;


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

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


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

解决方案

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

这篇关于几GB后,可恢复的上传会被中止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆