php-上传的图片未在Google云端存储上设为公开-Google App Engine
作者:互联网
我在这里遇到问题.我确实遵循了Google app-engine – Uploaded files not public on google cloud storage的两个答案,但是仍然没有运气.每当将图片上传到存储桶时,该图片均未设置为公开
这是我的代码:
// Google API to create an absolute URL that can be used by a user to asynchronously upload a large blob
require_once 'google/appengine/api/cloud_storage/CloudStorageTools.php';
use google\appengine\api\cloud_storage\CloudStorageTools;
// The name of cloud storage bucket
$options = [ 'gs_bucket_name' => 'example_images' ];
$upload_url = CloudStorageTools::createUploadUrl('/test.php', $options);
$fileName = 'gs://example_images/'.$_FILES['file']['name'];
echo $fileName."\n";
$options = array('gs'=>array('acl'=>'public-read','Content-Type' => $_FILES['file']['type']));
$ctx = stream_context_create($options);
if (false == rename($_FILES['file']['tmp_name'], $fileName, $ctx)) {
die('Could not rename.');
}
$object_public_url = CloudStorageTools::getPublicUrl($fileName, false);
print("Successfull! ");
我做错了什么?请帮我
解决方法:
最简单的方法是更改该存储桶上的默认对象ACL:
>前往https://console.developers.google.com/project/_/storage/browser
>单击存储桶名称右侧的按钮,该按钮看起来像3个垂直点
>单击编辑对象默认权限
>将allUsers添加为具有读取权限的用户
我在python项目like this中使用了它(在php中可能类似):
"acl": [{"entity": "allUsers", "role": "READER"}],
"contentType": "application/pdf",
"contentEncoding": "UTF8"
标签:google-cloud-storage,google-app-engine,php 来源: https://codeday.me/bug/20191027/1947280.html