繁体   English   中英

将图片文件上传到Google云存储

[英]upload image file to google cloud storage

我正在尝试按照此处的google cloud storage文档将图像文件上传到google cloud storage,但是没有成功。

我在Google云端存储中创建的存储桶名为:test_app-111

这是我的app.yaml文件:

application: test_app-111  
version: 1
runtime: php
api_version: 1

handlers:

# Serve images as static resources.
- url: /(.+\.(gif|png|jpg))$
  static_files: \1
  upload: .+\.(gif|png|jpg)$
  application_readable: true

- url: /img.php
  script: img.php 

这是我的php文件,名为img.php

<?php

require_once 'google/appengine/api/cloud_storage/CloudStorageTools.php';
use google\appengine\api\cloud_storage\CloudStorageTools;

$options = [ 'gs_bucket_name' => 'https://storage.googleapis.com/test_app-111.appspot.com' ];
$upload_url = CloudStorageTools::createUploadUrl('/upload_handler.php', $options);

?>


<form action="<?php echo $upload_url?>" enctype="multipart/form-data" method="post">
    Files to upload: <br>
   <input type="file" name="uploaded_files" size="40">
   <input type="submit" value="Send">
</form>

知道我想念什么吗? 在文档中说“使用CloudStorageTools :: createUploadUrl()方法创建应用程序特定的上载URL”。 我需要自己创建一个上传网址吗? 任何人都知道如何继续前进吗?

gs_bucket_name应该设置为您的存储桶名称,而不是完整的网址,即

$options = [ 'gs_bucket_name' => 'test_app-111.appspot.com' ];

您也可以使用CloudStorageTools::getDefaultGoogleStorageBucketName()来检索默认存储桶名称,而不是使用硬编码。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM