加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 无法使用谷歌API将对象上传到谷歌云存储

发布时间:2020-12-13 17:13:23 所属栏目:PHP教程 来源:网络整理
导读:我使用以下链接来使用Google云端存储: Google CLoud 我想使用上面API中给出的插入函数上传一个对象.我正在使用PHP.我使用的代码如下: $StorageService = new Google_StorageService($client);$objects = $StorageService-objects;$gso = new Google_Storag
我使用以下链接来使用Google云端存储:

Google CLoud

我想使用上面API中给出的插入函数上传一个对象.我正在使用PHP.我使用的代码如下:

$StorageService = new Google_StorageService($client);
$objects = $StorageService->objects;
$gso = new Google_StorageObject();
$gso->setName('myobj');
$postbody = array(file_get_contents('buc.jpg'));
$resp = $objects->insert('mybucket',$gso,$postbody);

但我得到错误:

致命错误:第66行的/home/www/public_html/abc/google-api-php-client/src/io/Google_REST.php中显示消息“Google_ServiceException”,并显示错误“错误调用POST https://www.googleapis.com/storage/v1beta1/b/mybucket/o:(400)必需”

我做错了什么,请帮帮我..

我发送参数的方式存在一些问题.如果有人知道帮帮我..

这里有一个例子:

Example

但那是在Java中请帮我在PHP中做同样的事情.请帮帮我.

解决方法

我想出了答案.要使用的代码如下:

$objects = $StorageService->objects;
$postbody = array('data' => file_get_contents('buc.jpg'));
$gso = new Google_StorageObject();
$gso->setName('mybuc');
$resp = $objects->insert('mybucket',$postbody);
print_r($resp);

然后它的工作..我没有在数组中设置参数“data”作为函数的第三个参数传递.我找到了它并且它有效.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读