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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With