Make requests and handle responses for resumable upload: Google Drive api [php]

后端 未结 2 696
臣服心动
臣服心动 2021-01-11 12:55

I\'m using the API Client Library for PHP (Beta) to work with google drive api, So far I can authorize and and upload a file in chuncks. According to the documentation, thes

2条回答
  •  再見小時候
    2021-01-11 14:01

    On the first instance, make an upload call and get the resumeUri:

      $chunk  = fread($handle, 1*1024*1024);
      $result = $media->nextChunk($chunk);
    
      $resumeUri = $media->getResumeUri();
      $offset    = ftell($handle);
    

    On the second instance use the same resumeUri to resume the upload from where we left out by calling resume() function before nextChunk() function:

     if ($resumeUri) {
        $media->resume($resumeUri);
     }
    
     fseek($handle, $offset);       
     $chunk = fread($handle, 1*1024*1024);
    
     $result = $media->nextChunk($chunk);
    

    Repeat the process until the $result variable has truthy value.

提交回复
热议问题