upload image file to google cloud storage

强颜欢笑 提交于 2019-12-08 04:16:01

问题


I was trying to upload an image file to google cloud storage, following the google cloud storage documentation here, but without success.

The bucket that I created in my google cloud storage is named: test_app-111

This is my app.yaml file:

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 

This is my php file called 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>

Any idea what am I missing? In the documentation it says "Create the application specific upload URL, using the method CloudStorageTools::createUploadUrl()". Do I have to create myself an upload URL? Anyone got an idea how to move on?


回答1:


gs_bucket_name should be set to your bucket name, not the full url, i.e.

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

You can also use CloudStorageTools::getDefaultGoogleStorageBucketName() to retrieve the default bucket name instead of hard-coding in one.



来源:https://stackoverflow.com/questions/27744548/upload-image-file-to-google-cloud-storage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!