Paste an object into Google Cloud Storage using PHP

Honestly, I'm really disappointed with the lack of a Google Cloud Storage document with PHP. Most of what I found here (Stackoverflow) is deprecated.

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); 

Error message

(400) Send requests must be sent to / upload / *. Resend the request to the same path, but with the / upload prefix.

From the 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 can I do this using the Google Cloud Storage client API?

+7
google-cloud-storage php
source share
1 answer

I managed to create a small script that uploads large files to GCS.

I used the Google APIs client library API for PHP

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

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

I really use it on many sites and work great.

+2
source share

All Articles