src/GoogleDriveAdapter.php
protected function uploadResourceToGoogleDrive($resource, $parentId, $fileName, $srcDriveFile, $mime)
    {
        $chunkSizeBytes = $this->detectChunkSizeBytes();
        $fileSize = $this->getFileSizeBytes($resource);

        if ($fileSize <= $chunkSizeBytes) {
            // If the resource fits in a single chunk, we'll just upload it in a single request
            return $this->uploadStringToGoogleDrive(stream_get_contents($resource), $parentId, $fileName, $srcDriveFile, $mime);
        }

        $client = $this->service->getClient();
        // Call the API with the media upload, defer so it doesn't immediately return.
        $client->setDefer(true);
        $request = $this->ensureDriveFileExists('', $parentId, $fileName, $srcDriveFile, $mime);
        $client->setDefer(false);
        $media = $this->getMediaFileUpload($client, $request, $mime, $chunkSizeBytes);
        $media->setFileSize($fileSize);

        // Upload chunks until we run out of file to upload; $status will be false until the process is complete.
        $status = false;
        while (! $status && ! feof($resource)) {
            $chunk = $this->readFileChunk($resource, $chunkSizeBytes);
            $status = $media->nextChunk($chunk);
        }

        // The final value of $status will be the data from the API for the object that has been uploaded.
        return $status;
    }
protected function uploadResourceToGoogleDrive($resource, $parentId, $fileName, $srcDriveFile, $mime)
    {
        $chunkSizeBytes = $this->detectChunkSizeBytes();
        $fileSize = $this->getFileSizeBytes($resource);

        if ($fileSize <= $chunkSizeBytes) {
            // If the resource fits in a single chunk, we'll just upload it in a single request
            return $this->uploadStringToGoogleDrive(stream_get_contents($resource), $parentId, $fileName, $srcDriveFile, $mime);
        }

        $client = $this->service->getClient();
        // Call the API with the media upload, defer so it doesn't immediately return.
        $client->setDefer(true);
        $request = $this->ensureDriveFileExists('', $parentId, $fileName, $srcDriveFile, $mime);
        $client->setDefer(false);
        $media = $this->getMediaFileUpload($client, $request, $mime, $chunkSizeBytes);
        $media->setFileSize($fileSize);

        // Upload chunks until we run out of file to upload; $status will be false until the process is complete.
        $status = false;
        while (! $status && ! feof($resource)) {
            $chunk = $this->readFileChunk($resource, $chunkSizeBytes);
            $status = $media->nextChunk($chunk);
        }

        // The final value of $status will be the data from the API for the object that has been uploaded.
        return $status;
    }
protected function uploadResourceToGoogleDrive ( $ resource , $ parentId , $ fileName , $ srcDriveFile , $ mime ) { $ chunkSizeBytes = $ this -> detectChunkSizeBytes ( ) ; $ fileSize = $ this -> getFileSizeBytes ( $ resource ) ; if ( $ fileSize <= $ chunkSizeBytes ) { // If the resource fits in a single chunk, we'll just upload it in a single request return $ this -> uploadStringToGoogleDrive ( stream_get_contents ( $ resource ) , $ parentId , $ fileName , $ srcDriveFile , $ mime ) ; } $ client = $ this -> service -> getClient ( ) ; // Call the API with the media upload, defer so it doesn't immediately return. $ client -> setDefer ( true ) ; $ request = $ this -> ensureDriveFileExists ( '' , $ parentId , $ fileName , $ srcDriveFile , $ mime ) ; $ client -> setDefer ( false ) ; $ media = $ this -> getMediaFileUpload ( $ client , $ request , $ mime , $ chunkSizeBytes ) ; $ media -> setFileSize ( $ fileSize ) ; // Upload chunks until we run out of file to upload; $status will be false until the process is complete. $ status = false ; while ( ! $ status && ! feof ( $ resource ) ) { $ chunk = $ this -> readFileChunk ( $ resource , $ chunkSizeBytes ) ; $ status = $ media -> nextChunk ( $ chunk ) ; } // The final value of $status will be the data from the API for the object that has been uploaded. return $ status ; }
Upload a PHP resource stream to Google Drive

@param resource $resource
@param string $parentId
@param string $fileName
@param string $mime
@return bool|Google_Service_Drive_DriveFile
Upload a PHP resource stream to Google Drive