Google Drive API GuzzleHttp\Exception\RequestException - php

Following the instructions for these topics:
https://github.com/google/google-api-php-client/issues/788
https://developers.google.com/api-client-library/php/guide/media_upload
I tried to fix the problem below and upload files to Google Drive:
Fatal error: Uncaught GuzzleHttp\Exception\RequestException: cURL error 60: SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed (see http://curl.haxx.se/libcurl/c/libcurl-errors.html) in /secret/public_html/v5/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php:187 Stack trace: #0 /secret/public_html/v5/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php(150): GuzzleHttp\Handler\CurlFactory::createRejection(Object(GuzzleHttp\Handler\EasyHandle), Array) #1 /secret/public_html/v5/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php(103): GuzzleHttp\Handler\CurlFactory::finishError(Object(GuzzleHttp\Handler\CurlHandler), Object(GuzzleHttp\Handler\EasyHandle), Object(GuzzleHttp\Handler\CurlFactory)) #2 /secret/public_html/v5/vendor/guzzlehttp/guzzle/src/Handler/CurlHandler.php(43): GuzzleHttp\Handler\CurlFactory::fin in /secret/public_html/v5/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php on line 187
Using the APIs in PHP, when the file is less than 5 MB, it does not show the error, however, files larger than this generate the above error. Is the problem the API or the certificate? Even installing it on my linux server the error continues, does anyone know how to fix this problem? Or have you ever faced something like that?
Here is the code I'm using to upload up to 5 MB that is working.
<?php
$client = new Google_Client();
$client->setAuthConfig("client_secret.json");
$client->setIncludeGrantedScopes(true);
$client->setAccessType("offline");
$client->setAccessToken($access_token);
$drive_service = new Google_Service_Drive($client);
$mime_type = mime_content_type($uploadfile);
$file = new Google_Service_Drive_DriveFile();
$result = $drive_service->files->create($file, array(
"data" => file_get_contents($uploadfile),
"mimeType" => $mime_type,
"uploadType" => "media"
));
Following is the code I'm using to upload a larger 5 MB that is not working.
<?php
$client = new Google_Client();
$client->setAuthConfig("client_secret.json");
$client->setIncludeGrantedScopes(true);
$client->setAccessType("offline");
$client->setAccessToken($access_token);
$drive_service = new Google_Service_Drive($client);
$mime_type = mime_content_type($uploadfile);
$file = new Google_Service_Drive_DriveFile();
$file->title = $uploadname;
$chunkSizeBytes = 1 * 1024 * 1024;
$client->setDefer(true);
$request = $drive_service->files->create($file); // insert
$media = new Google_Http_MediaFileUpload($client, $request, $mime_type, null, true, $chunkSizeBytes);
$media->setFileSize(filesize($uploadfile));
$status = false;
$handle = fopen($uploadfile, "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);

Related

Upload files to dropbox with php - Dropbox-SDK-PHP

im a beginer and i traying to upload files to dropbox using dropbox-sdk-php
this is the code that I am using
live test : http://test.dedragon.net
$dropboxKey ='MY_KEY';
$dropboxSecret ='MY_SECRET';
$appName='MY_APPNAME';
$acessToken = "MY_ACCESTOKEN";
set_error_handler('error');
$appInfo = new Dropbox\AppInfo($dropboxKey,$dropboxSecret);
//Store CSRF token
$csrfTokenStore = new Dropbox\ArrayEntryStore($_SESSION['k6'],'dropbox-auth');
//define auth details
$webAuth = new Dropbox\WebAuth($appInfo,$appName,'http://test.dedragon.net',$csrfTokenStore);
$client = new Dropbox\client($acessToken,$appName,'UTF-8');
//time to upload file
if (!empty($_FILES)) {
$nombre = uniqid();
$tempFile = $_FILES['file']['tmp_name'];
$f = fopen($_FILES['file']['tmp_name'], "rb");
$ext = explode(".", $_FILES['file']['name']);
$ext =end($ext);
$nombredropbox = "/". $nombre .'.'.$ext;
$tama = explode(".", $_FILES['file']['size']);
try{
$client->uploadFile($nombredropbox,Dropbox\WriteMode::add(),$f);
}catch(Dropbox\Exception_InvalidAccessToken $e){
error('001',$e);
}
}
function error($numero,$texto){
$ddf = fopen('error.log','a');
fwrite($ddf,"[".date("r")."] Error $numero: $texto\r\n");
fclose($ddf);
}
shows me Status Code: 500
and Error appear
[05-Jun-2019 09:08:13 UTC] PHP Fatal error: Uncaught Dropbox\Exception_BadRequest: HTTP status 400
{"error": "v1_retired"} in /home/jjddqqslmq4q/public_html/test/terceros/dropbox/vendor/dropbox/dropbox-sdk/lib/Dropbox/RequestUtil.php:250
Stack trace:
#0 /home/jjddqqslmq4q/public_html/test/terceros/dropbox/vendor/dropbox/dropbox-sdk/lib/Dropbox/Client.php(558): Dropbox\RequestUtil::unexpectedStatus(Object(Dropbox\HttpResponse))
#1 /home/jjddqqslmq4q/public_html/test/terceros/dropbox/vendor/dropbox/dropbox-sdk/lib/Dropbox/Client.php(423): Dropbox\Client->chunkedUploadStart('%PDF-1.5\r\n%\xB5\xB5\xB5\xB5...')
#2 /home/jjddqqslmq4q/public_html/test/terceros/dropbox/vendor/dropbox/dropbox-sdk/lib/Dropbox/RequestUtil.php(279): Dropbox\Client->Dropbox\{closure}()
#3 /home/jjddqqslmq4q/public_html/test/terceros/dropbox/vendor/dropbox/dropbox-sdk/lib/Dropbox/Client.php(424): Dropbox\RequestUtil::runWithRetry(3, Object(Closure))
#4 /home/jjddqqslmq4q/public_html/test/terceros/dropbox/vendor/dropbox/dropbox-sdk/lib/Dropbox/Client.php(286): Dropbox\Client->_upload in /home/jjddqqslmq4q/public_html/test/terceros/dropbox/vendor/dropbox/dropbox-sdk/lib/Dropbox/RequestUtil.php on line 250
[05-Jun-2019 09:11:52 UTC] PHP Fatal error: Uncaught Dropbox\Exception_BadRequest: HTTP status 400
I changed the SDK to https://github.com/kunalvarma05/dropbox-php-sdk.
<?php
require_once("terceros/dropbox/vendor/autoload.php");
use Kunnu\Dropbox\Dropbox;
use Kunnu\Dropbox\DropboxApp;
use Kunnu\Dropbox\DropboxFile;
$dropboxKey ='MY_KEY';
$dropboxSecret ='MY_SECRET';
$acessToken = "MY_TOKEN";
set_error_handler('error');
$app = new DropboxApp($dropboxKey,$dropboxSecret,$acessToken);
$dropbox = new Dropbox($app);
if (!empty($_FILES)) {
$nombre = uniqid();
$tempFile = $_FILES['file']['tmp_name'];
$ext = explode(".", $_FILES['file']['name']);
$ext =end($ext);
$nombredropbox = "/". $nombre .'.'.$ext;
TRY{
$file = $dropbox->simpleUpload($tempFile,$nombredropbox, ['autorename' => true]);
//Uploaded File
}CATCH(\EXCEPTION $E){
ERROR('001',$E);
}
}
function error($numero,$texto){
$ddf = fopen('error.log','a');
fwrite($ddf,"[".date("r")."] Error $numero: $texto\r\n");
fclose($ddf);
}
?>

Google drive API 403 insufficent permission error (do I need a google for work account?)

I would like to create an application to add folders and data inside those folders in Google Drive.
I am succesfully creating an acccess token using the refresh_token value. I am attempting to do a very basic file upload but its failing. I am also getting a list of files just to see is anything else working and that certainly is.
After the list of files appear I get the following error...
Fatal error: Uncaught exception 'Google_Service_Exception' with
message 'Error calling POST
https://www.googleapis.com/upload/drive/v3/files?uploadType=media:
(403) Insufficient Permission' in
/var/www/html/google-api-php-client/src/Google/Http/REST.php:110
Stack trace: #0
/var/www/html/google-api-php-client/src/Google/Http/REST.php(62):
Google_Http_REST::decodeHttpResponse(Object(Google_Http_Request),
Object(Google_Client))
1 [internal function]: Google_Http_REST::doExecute(Object(Google_Client),
Object(Google_Http_Request))
2 /var/www/html/google-api-php-client/src/Google/Task/Runner.php(174):
call_user_func_array(Array, Array)
3 /var/www/html/google-api-php-client/src/Google/Http/REST.php(46): Google_Task_Runner->run()
4 /var/www/html/google-api-php-client/src/Google/Client.php(593): Google_Http_REST::execute(Object(Google_Client),
Object(Google_Http_Request))
5 /var/www/html/google-api-php-client/src/Google/Service/Resource.php(240):
Google_Client->execute(Object(Google_H in
/var/www/html/google-api-php-client/src/Google/Http/REST.php on line
110
UPDATE: I tried this without using refresh_token too and simply using the latest access token but still getting the exact same error.
Initially setting up access to get myself to the consent screen...
require_once ('../autoload.php');
ini_set('display_errors',1);
error_reporting(E_ALL);
session_start();
$client = new Google_Client();
$client->setAuthConfig('client_secret.json');
$client->addScope("https://www.googleapis.com/auth/drive");
$client->setAccessType('offline');
$client->setApprovalPrompt('force');
$client->setRedirectUri('http://www.example.com/oauth2callback.php');
if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
print_r($_SESSION);
$client->setAccessToken($_SESSION['access_token']);
$drive_service = new Google_Service_Drive($client);
//$files_list = $drive_service->files->listFiles(array())->getItems();
//echo json_encode($files_list);
} else {
$redirect_uri = 'http:/www.example.com/google-api-php-client/oauth2callback.php';
header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
}
And then attempting to upload the file
error_reporting(E_ALL); ini_set('display_errors', 1);
require_once ('../autoload.php');
session_start();
$client = new Google_Client();
$client->setAuthConfigFile('client_secret.json');
$client->setAccessType('offline');
$client->setApprovalPrompt('force');
// this token is obtained the first time from refresh_token, it will not be shown after the initial requrest
$refreshToken ='xxx';
$client->refreshToken($refreshToken);
$service = new Google_Service_Drive($client);
$files_list = $service->files->listFiles(array())->getFiles();
echo '<pre>';
print_r($files_list);
echo '</pre>';
$client->addScope("https://www.googleapis.com/auth/drive");
DEFINE("TESTFILE", 'testfile-small.txt');
if (!file_exists(TESTFILE)) {
$fh = fopen(TESTFILE, 'w');
fseek($fh, 1024 * 1024);
fwrite($fh, "!", 1);
fclose($fh);
}
if ($client->getAccessToken()) {
// This is uploading a file directly, with no metadata associated.
$file = new Google_Service_Drive_DriveFile();
$result = $service->files->create(
$file,
array(
'data' => file_get_contents(TESTFILE),
'mimeType' => 'application/octet-stream',
'uploadType' => 'multipart'
)
);
}

Files updates no longer works using the google-api-php-client

I have a very small script that uploads and / or update files (wrote this about 1 year ago, borrowed 80% of the lines from the examples)
No major changes in the code since march (using 1.0.0-alpha) but mid-may the file updates stopped working, raising an Internal Server Error , i upgraded to 1.0.4-beta with no success :
PHP Fatal error: Uncaught exception 'Google_Service_Exception' with message 'Error calling PUT https://www.googleapis.com/upload/drive/v2/ [...] (500) Internal Error' in
google-api-php-client-1.0.4-beta/src/Google/Http/REST.php:80
code:
$client->setDefer(true);
$request = $service->files->update($update_id,$file);
$media = new Google_Http_MediaFileUpload(
$client,
$request,
'text/plain',
null,
true,
$chunkSizeBytes
);
$media->setFileSize(filesize($csvfile))
$status = false;
$handle = fopen($csvfile, "rb");
while (!$status && !feof($handle)) {
$chunk = fread($handle, $chunkSizeBytes);
$status = $media->nextChunk($chunk);
}
File inserts (HTTP POST) are still working (using the same code for uploading the chunks)
any ideas ?
I can update a file ( previously created or copied from a template ) with this code :
(...)
require_once 'src/Google/Client.php';
require_once 'src/Google/Service/Oauth2.php';
require_once 'src/Google/Service/Drive.php';
(...)
$client = new Google_Client();
// set scopes ...
(...)
$GDrive_service = new Google_Service_Drive($client);
(...)
// then I set parameters
(...)
$newTitle = $title ;
$newDescription = $description ;
$newMimeType = 'text/csv' ;
$newFileName = $filename ;
$service = $GDrive_service ;
(...)
$updatedFile = updateFile($service, $fileId, $newTitle, $newDescription, $newMimeType, $newFileName, $newRevision) ;
function updateFile($service, $fileId, $newTitle, $newDescription, $newMimeType, $newFileName, $newRevision) {
try {
// First retrieve the file from the API.
$file = $service->files->get($fileId);
// File's new metadata.
$file->setTitle($newTitle);
$file->setDescription($newDescription);
$file->setMimeType($newMimeType);
// File's new content.
$data = file_get_contents($newFileName);
$convert = 'true' ;
$additionalParams = array(
'uploadType' => 'multipart',
'newRevision' => $newRevision,
'data' => $data,
'mimeType' => $newMimeType,
'convert' => $convert,
);
// Send the request to the API.
$updatedFile = $service->files->update($fileId, $file, $additionalParams);
return $updatedFile;
} catch (Exception $e) {
print "An error occurred: " . $e->getMessage();
}
}
(...)
// this is info of the updated file
$fileId = $updatedFile->getId() ;
// link of file
$cF_link = $updatedFile->alternateLink ;
// pdf version
$enllacos = $updatedFile->exportLinks ;
$cF_PDF_link = $enllacos['application/pdf'] ;
(...)
This code is working with the 1.0.5-beta php client
Sergi

Google API's php client library - YouTube chunked upload ERROR

I'm using Google API's PHP client library and when I use this solution:
https://stackoverflow.com/a/14552052/1181479
and the same as here
https://developers.google.com/youtube/v3/code_samples/php#resumable_uploads
witch contain such logic:
if ($client->getAccessToken()) {
$videoPath = "path/to/foo.mp4";
$snippet = new Google_VideoSnippet();
$snippet->setTitle("Test title2");
$snippet->setDescription("Test descrition");
$snippet->setTags(array("tag1", "tag2"));
$snippet->setCategoryId("22");
$status = new Google_VideoStatus();
$status->privacyStatus = "private";
$video = new Google_Video();
$video->setSnippet($snippet);
$video->setStatus($status);
$chunkSizeBytes = 1 * 1024 * 1024;
$media = new Google_MediaFileUpload('video/mp4', null, true, $chunkSizeBytes);
$media->setFileSize(filesize($videoPath));
$result = $youtube->videos->insert("status,snippet", $video,
array('mediaUpload' => $media));
$status = false;
$handle = fopen($videoPath, "rb");
while (!$status && !feof($handle)) {
$chunk = fread($handle, $chunkSizeBytes);
$uploadStatus = $media->nextChunk($result, $chunk);
}
fclose($handle);
}
The main problem is this error:
ErrorException [ Recoverable Error ]: Argument 1 passed to Google_MediaFileUpload::nextChunk() must be an instance of Google_HttpRequest, instance of Google_Video given, called in /opt/code/host/resulinkpro/www/application/classes/Controller/Upload.php on line 132 and defined
the core of that stuff is:
$media is Google_Video class
and
$media->nextChunk($result, $chunk);
requires $result to be Google_HttpRequest SO Google documentation and any example in web will not help to achieve that task at all! Last chance on you guys!
Thank you!
Both of the examples were made for PHP client 0.6.3, I believe you are trying it with 1.0 version. You can read about migrating here.
We hope to post the updated examples really soon.

Getting a video from S3 and Uploading to YouTube in PHP

I have some code working that uploads a video file up to YouTube:
$yt = new Zend_Gdata_YouTube($httpClient);
// create a new VideoEntry object
$myVideoEntry = new Zend_Gdata_YouTube_VideoEntry();
// create a new Zend_Gdata_App_MediaFileSource object
$filesource = $yt->newMediaFileSource('file.mov');
$filesource->setContentType('video/quicktime');
// set slug header
$filesource->setSlug('file.mov');
I have videos in S3 and I want to upload them to YouTube. The video in our S3 account is public, so i can use a command like wget. Should I run a command that wgets the video file and downloads it locally before I run this script (shell_exec("wget ".$s3videoURL))?
Or should I try to enter the MediaFileSource as the URL of the S3 file itself?
Mainly, I just need stability (not a solution subject to frequent time-outs); speed and local storage isn't really important (I can locally delete video file once its been uploaded).
What would be the best way to go about this?
Thanks!
Update: I should probably mention that this script is going to be uploading about 5 videos to YouTube per execution.
This is an old question but i believe i have a better answer.
You don't have to write video to HDD and you can't keep the whole thing in RAM (I assume it is a big file).
You can use PHP AWS SDK and Google Client libraries to buffer file from S3 and send it to YouTube on the fly. Use registerStreamWrapper method to register S3 as file system and use resumable uploads from YouTube API. Then all you have to do is reading chunks from S3 with fread and sending them to YouTube. This way you can even limit the RAM usage.
I assume you created the video object ($video in code) from Google_Video class. This is a complete code.
<?php
require_once 'path/to/libraries/aws/vendor/autoload.php';
require_once 'path/to/libraries/google-client-lib/autoload.php';
use Aws\S3\S3Client;
$chunkSizeBytes = 2 * 1024 * 1024; // 2 mb
$streamName = 's3://bucketname/video.mp4';
$s3client = S3Client::factory(array(
'key' => S3_ACCESS_KEY,
'secret' => S3_SECRET_KEY,
'region' => 'eu-west-1' // if you need to set.
));
$s3client->registerStreamWrapper();
$client = new Google_Client();
$client->setClientId(YOUTUBE_CLIENT_ID);
$client->setClientSecret(YOUTUBE_CLIENT_SECRET);
$client->setAccessToken(YOUTUBE_TOKEN);
$youtube = new Google_YoutubeService($client);
$media = new Google_MediaFileUpload('video/*', null, true, $chunkSizeBytes);
$filesize = filesize($streamName); // use it as a reguler file.
$media->setFileSize($filesize);
$insertResponse = $youtube->videos->insert("status,snippet", $video, array('mediaUpload' => $media));
$uploadStatus = false;
$handle = fopen($streamName, "r");
$totalReceived = 0;
$chunkBuffer = '';
while (!$uploadStatus && !feof($handle)) {
$chunk = fread($handle, $chunkSizeBytes);
$chunkBuffer .= $chunk;
$chunkBufferSize = strlen($chunkBuffer);
if($chunkBufferSize > $chunkSizeBytes) {
$fullChunk = substr($chunkBuffer, 0, $chunkSizeBytes);
$leapChunk = substr($chunkBuffer, $chunkSizeBytes);
$uploadStatus = $media->nextChunk($insertResponse, $fullChunk);
$totalSend += strlen($fullChunk);
$chunkBuffer = $leapChunk;
echo PHP_EOL.'Status: '.($totalReceived).' / '.$filesize.' (%'.(($totalReceived / $filesize) * 100).')'.PHP_EOL;
}
$totalReceived += strlen($chunk);
}
$extraChunkLen = strlen($chunkBuffer);
$uploadStatus = $media->nextChunk($insertResponse, $chunkBuffer);
$totalSend += strlen($chunkBuffer);
fclose($handle);
The "MediaFileSource" must be a real file. It won't take a URL, so you will need to copy the videos to your server from S3, before sending them to YouTube.
You can probably get away with the "shell_exec" if your usage is light, but for a variety of reasons its probably better to use either the Zend S3 Service, or cURL to pull files from S3.
I had to make some changes to #previous_developer 's answer to make it work with Youtube Data API V3 (Please upvote him as I could not find any working code except his).
$streamName = 's3://BUCKET-NAME/VIDEO.mp4';
/**
Since I have been using Yii 2. Use the AWS
SDK directly instead.
*/
$aws = Yii::$app->awssdk->getAwsSdk();
$s3client = $aws->createS3();
$s3client->registerStreamWrapper();
$service = new \Google_Service_YouTube($client);
$snippet = new \Google_Service_YouTube_VideoSnippet();
$snippet->setTitle("Test title");
$snippet->setDescription("Test descrition");
$snippet->setTags(array("tag1","tag2"));
$snippet->setCategoryId("22");
$status = new \Google_Service_YouTube_VideoStatus();
$status->privacyStatus = "public";
$video = new \Google_Service_YouTube_Video();
$video->setSnippet($snippet);
$video->setStatus($status);
$client->setDefer(true);
$insertResponse = $service->videos->insert("status,snippet", $video);
$media = new MediaFileUpload(
$client,
$insertResponse,
'video/*',
null,
true,
false
);
$filesize = filesize($streamName); // use it as a reguler file.
$media->setFileSize($filesize);
$chunkSizeBytes = 2 * 1024 * 1024; // 2 mb
$uploadStatus = false;
$handle = fopen($streamName, "r");
$totalSend = 0;
$totalReceived = 0;
$chunkBuffer = '';
while (!$uploadStatus && !feof($handle)) {
$chunk = fread($handle, $chunkSizeBytes);
$chunkBuffer .= $chunk;
$chunkBufferSize = strlen($chunkBuffer);
if($chunkBufferSize > $chunkSizeBytes) {
$fullChunk = substr($chunkBuffer, 0, $chunkSizeBytes);
$leapChunk = substr($chunkBuffer, $chunkSizeBytes);
$uploadStatus = $media->nextChunk($fullChunk);
$totalSend += strlen($fullChunk);
$chunkBuffer = $leapChunk;
echo PHP_EOL.'Status: '.($totalReceived).' / '.$filesize.' (%'.(($totalReceived / $filesize) * 100).')'.PHP_EOL;
}
$totalReceived += strlen($chunk);
}
$extraChunkLen = strlen($chunkBuffer);
$uploadStatus = $media->nextChunk($chunkBuffer);
$totalSend += strlen($chunkBuffer);
fclose($handle);
// If you want to make other calls after the file upload, set setDefer back to false
$client->setDefer(false);
$chunkSizeBytes = 2 * 1024 * 1024; // 2 mb
$s3client = $this->c_aws->getS3Client();
$s3client->registerStreamWrapper();
try {
$client = new \Google_Client();
$client->setAccessType("offline");
$client->setApprovalPrompt('force');
$client->setClientId(GOOGLE_CLIENT_ID);
$client->setClientSecret(GOOGLE_CLIENT_SECRET);
$token = $client->fetchAccessTokenWithRefreshToken(GOOGLE_REFRESH_TOKEN);
$client->setAccessToken($token);
$youtube = new \Google_Service_YouTube($client);
// Create a snippet with title, description, tags and category ID
// Create an asset resource and set its snippet metadata and type.
// This example sets the video's title, description, keyword tags, and
// video category.
$snippet = new \Google_Service_YouTube_VideoSnippet();
$snippet->setTitle($title);
$snippet->setDescription($summary);
$snippet->setTags(explode(',', $keywords));
// Numeric video category. See
// https://developers.google.com/youtube/v3/docs/videoCategories/list
// $snippet->setCategoryId("22");
// Set the video's status to "public". Valid statuses are "public",
// "private" and "unlisted".
$status = new \Google_Service_YouTube_VideoStatus();
$status->privacyStatus = "public";
// Associate the snippet and status objects with a new video resource.
$video = new \Google_Service_YouTube_Video();
$video->setSnippet($snippet);
$video->setStatus($status);
// Setting the defer flag to true tells the client to return a request which can be called
// with ->execute(); instead of making the API call immediately.
$client->setDefer(true);
$insertRequest = $youtube->videos->insert("status,snippet", $video);
$media = new \Google_Http_MediaFileUpload(
$client,
$insertRequest,
'video/*',
null,
true,
$chunkSizeBytes
);
$result = $this->c_aws->getAwsFile($aws_file_path);
$media->setFileSize($result['ContentLength']);
$uploadStatus = false;
// Seek to the beginning of the stream
$result['Body']->rewind();
// Read the body off of the underlying stream in chunks
while (!$uploadStatus && $data = $result['Body']->read($chunkSizeBytes)) {
$uploadStatus = $media->nextChunk($data);
}
$client->setDefer(false);
if ($uploadStatus->status['uploadStatus'] == 'uploaded') {
// Actions to perform for a successful upload
$uploaded_video_id = $uploadStatus['id'];
return ($uploadStatus['id']);
}
}catch (\Google_Service_Exception $exception){
return '';
print_r($exception);
}

Categories