Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert object to Google Cloud Storage using PHP

To be honest, I am really frustrated with the lack of document of Google Cloud Storage with PHP. Most of what I found in here (Stackoverflow) is out of date.

Here is my attempt:

$postbody = array('data' => file_get_contents('e.png'));
$gso = new Google_Service_Storage_StorageObject();
$gso->setName('testing');
$gso->setContentType('images/png');

$service->objects->insert($bucket_name, $gso, $postbody);

The error message

(400) Upload requests must be sent to /upload/*. Re-send request to the same path, but with an /upload prefix.

From Google Cloud Storage JSON API, I understand that I need to use upload/storage/v1/b/bucket_name/o instead of storage/v1/b/bucket_name/o, but how do I do it with Google Cloud Storage PHP Client API?

like image 658
invisal Avatar asked Jun 02 '15 15:06

invisal


1 Answers

I managed to build a small script that uploads big files to GCS.

I used Google APIs Client Library for PHP

Find it in github https://github.com/guillefd/Backup-manager-gcs

This library manages the file upload (big files) https://github.com/guillefd/Backup-manager-gcs/blob/master/application/libraries/Googlecloudstorage.php

I´m actually using it in many sites and works quite fine.

like image 65
guillefd Avatar answered Nov 12 '22 04:11

guillefd