使用PHP将对象插入Google Cloud Storage [英] Insert object to Google Cloud Storage using PHP
问题描述
说实话,我对缺少使用PHP的Google Cloud Storage文档感到非常沮丧.我在这里(Stackoverflow)中发现的大多数内容都已过时.
这是我的尝试:
$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);
错误消息
(400)上传请求必须发送到/upload/*.将请求重新发送到同一路径,但带有/upload前缀.
从Google Cloud Storage JSON API可以理解,我需要使用upload/storage/v1/b/bucket_name/o
而不是storage/v1/b/bucket_name/o
,但是如何使用Google Cloud Storage PHP客户端API?
我设法构建了一个小脚本,该脚本将大文件上传到GCS.
在github中找到它 https://github.com/guillefd/Backup-manager-gcs
此库管理文件上传(大文件) 解决方案
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.
这篇关于使用PHP将对象插入Google Cloud Storage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!