我正尝试按照Google云存储文档此处,但没有成功.
I was trying to upload an image file to google cloud storage, following the google cloud storage documentation here, but without success.
我在Google云端存储中创建的存储桶名为:test_app-111
The bucket that I created in my google cloud storage is named: 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 :
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' => 'storage.googleapis/test_app-111.appspot' ]; $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".我需要自己创建一个上传网址吗?任何人都知道如何继续前进吗?
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?
推荐答案gs_bucket_name应该设置为您的存储桶名称,而不是完整的url,即
gs_bucket_name should be set to your bucket name, not the full url, i.e.
$options = [ 'gs_bucket_name' => 'test_app-111.appspot' ];您也可以使用CloudStorageTools::getDefaultGoogleStorageBucketName()来检索默认存储桶名称,而不是将其中一个进行硬编码.
You can also use CloudStorageTools::getDefaultGoogleStorageBucketName() to retrieve the default bucket name instead of hard-coding in one.
更多推荐
将图片文件上传到Google云存储
发布评论