【问题标题】:Uploaded image does not set to public on Google Cloud Storage - Google App Engine上传的图片未在 Google Cloud Storage 上设置为公开 - Google App Engine
【发布时间】:2016-01-09 08:06:33
【问题描述】:

我在这里遇到了问题。我确实遵循了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! ");

我做错了什么?请帮帮我

【问题讨论】:

    标签: php google-app-engine google-cloud-storage


    【解决方案1】:

    最简单的方法是更改​​该存储桶上的默认对象 ACL:

    1. 转到https://console.developers.google.com/project/_/storage/browser
    2. 点击bucket名称右侧看起来像3个垂直点的按钮
    3. 点击编辑对象默认权限
    4. 将 allUsers 添加为具有 READ 权限的用户

    我在一个python项目中使用过like this(在php中可能类似):

        "acl": [{"entity": "allUsers", "role": "READER"}],
        "contentType": "application/pdf",
        "contentEncoding": "UTF8"
    

    【讨论】:

      猜你喜欢
      • 2013-11-02
      • 2014-03-10
      • 2015-07-07
      • 2015-11-16
      • 2016-11-09
      • 2013-06-27
      • 1970-01-01
      • 2014-10-10
      • 1970-01-01
      相关资源
      最近更新 更多