图像上传到谷歌桶和云存储 [英] image upload to google bucket ay cloud storage

查看:85
本文介绍了图像上传到谷歌桶和云存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在测试以下代码,以查看是否可以将图像上传到Google的云存储桶中.

I was testing the following piece of code, to see If I can upload images to the bucket at google's cloud storage.

这是我的app.yaml文件:

This is my app.yaml file:

application: test-795  
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: /(.+\.php).*
  script: \1  

- url: /upload
  script: fileimage.php 

这是我的fileimage.php文件,用于将图像文件上传到存储桶:

and this is my fileimage.php file for uploading image file to bucket:

<?php

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

 $options = [ 'gs_bucket_name' => 'test-795.appspot.com' ];
 $upload_url = CloudStorageTools::createUploadUrl('/upload', $options);

   if(isset($_POST['do-upload']) AND $_POST['do-upload'] === "yes"){

   $yesupload = $_POST['do-upload'];
   preg_match("/yes/", "".$yesupload."");

   $filename = $_FILES['testupload']['name'];

   $gs_name = $_FILES['testupload']['tmp_name'];
   move_uploaded_file($gs_name, 'gs://test-795.appspot.com/'.$filename.'');
?>

<div class="contentArea">
<?php
echo "<p class=\"SomeSpaceDude\">Hey file is uploaded, Yes! ".$yesupload." !</p>";
echo "<p class=\"SomeSpaceDude\">This is the file name: ".$filename."</p>";
}

echo"</div>";
?>

<form class="SomeSpaceDude" action="<?php echo $upload_url?>" enctype="multipart/form-data" method="post">
<p>Files to upload: </p> <br>
 <input type="hidden" name="do-upload" value="yes">
 <input class="SomeSpaceDude topcoat-button" type="file" name="testupload" >
 <input class="SomeSpaceDude topcoat-button" type="submit" value="Upload">
</form>
</div>

当我使用localhost:8080运行文件时,收到消息嘿文件已上传,是的!是的!我的网址变成:localhost:8080/_ah/upload/ahVkZXZ-Y ... 在Google存储库中检查我的存储桶,其名称为test-795,什么都没有上传.

when I run the file using localhost:8080 i get the message Hey file is uploaded, Yes! yes ! My web address becoming like : localhost:8080/_ah/upload/ahVkZXZ-Y... Checking on my bucket at google storage which has the name test-795 and nothing is uploaded.

我也已经部署了它,按下上传按钮后对其进行测试时,我得到一个空白页,并且网址链接看起来像是:test-795.appspot.com/_ah/upload/AMmfu6 ...当然,什么也没装进去. 知道我在这里想念什么吗?

I have also deploy it, and when I test it after pressing upload button, I get an empty page and web address link looks like: test-795.appspot.com/_ah/upload/AMmfu6... Checking at my bucket nothing inside again ofcourse. Any idea what am I missing here?

推荐答案

在开发服务器中运行时,该文件不会上载到真正的Cloud Storage服务,而只会上传到本地仿真.

When you're running in the development server the file does not get uploaded to the real Cloud Storage service, only a local emulation.

在生产服务器上,检查日志以查看上载可能发生的情况.

On the production server, check the logs to see what might be happening with your upload.

这篇关于图像上传到谷歌桶和云存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆