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

编程入门 行业动态 更新时间:2024-10-08 14:43:02
本文介绍了将图片文件上传到Google云存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正尝试按照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云存储

本文发布于:2023-11-24 14:05:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1625523.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件上传   图片   Google

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!