PHP: can't upload files to google cloud storage! (error 400) -


i've written short php script in order upload local file google cloud storage bucket, using php client library (https://github.com/google/google-api-php-client). can authenticate, can list remote content, can't upload anything, since obtain error 400 ("uploads must sent upload url").

this full script, modified following tutorial found online:

<?php require_once "/var/www/local/google-api-php-client-master/src/google/autoload.php"; // api google library  define('gapi_client_id', 'xxx.apps.googleusercontent.com'); define('gapi_email_address', 'yyy@developer.gserviceaccount.com'); define('gapi_api_key', 'xxxmyapikeyxxx'); define('gapi_project_id', 'projectid');  // certificate file define('key_file_location', '/var/www/local/passphrase.p12');  // bucket name $bucket = "mybucketname" // remote file name $file_name = "test.mp3"; // file upload $local_file = "/var/www/local/test.mp3";  $google_cert = new google_auth_assertioncredentials(  gapi_email_address,  array('https://www.googleapis.com/auth/devstorage.full_control'),  file_get_contents(key_file_location) );  $google_client = new google_client(); $google_client->setassertioncredentials($google_cert); $google_client->setdeveloperkey(gapi_api_key);  $service = new google_service_storage($google_client);  $obj = new google_service_storage_storageobject(); $obj->setname($file_name); $obj->setcontenttype('media'); $obj->setsize(filesize($local_file));  $datafile['data']=file_get_contents($local_file); $datafile['uploadtype']="media";  $service->objects->insert(  $bucket,  $obj,  $datafile );  ?> 

what's wrong it??


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -