简体   繁体   English

图像上传到谷歌桶和云存储

[英]image upload to google bucket ay cloud storage

I was testing the following piece of code, to see If I can upload images to the bucket at google's cloud storage. 我正在测试以下代码,以查看是否可以将图像上传到Google的云存储桶中。

This is my app.yaml file: 这是我的app.yaml文件:

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 

and this is my fileimage.php file for uploading image file to bucket: 这是我的fileimage.php文件,用于将图像文件上传到存储桶:

<?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>

when I run the file using localhost:8080 i get the message Hey file is uploaded, Yes! 当我使用localhost:8080运行文件时,我收到消息嘿文件已上传,是的! 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. 我的网址变得像:localhost:8080 / _ah / upload / ahVkZXZ-Y ...在Google存储区中检查我的存储桶,其名称为test-795,但未上传任何内容。

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. 我也已经部署了它,按下上传按钮后对其进行测试时,我得到一个空白页,并且网址链接看起来像是:test-795.appspot.com/_ah/upload/AMmfu6 ...在我的存储桶中没有任何检查当然了。 Any idea what am I missing here? 知道我在这里想念什么吗?

When you're running in the development server the file does not get uploaded to the real Cloud Storage service, only a local emulation. 在开发服务器中运行时,文件不会上载到真正的Cloud Storage服务,而只会上载到本地仿真。

On the production server, check the logs to see what might be happening with your upload. 在生产服务器上,检查日志以查看上载可能发生的情况。

上面的代码正常工作...我终于发现问题是,我应该在上面的代码test-795中使用各处,而不是test-795.appspot.com

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

相关问题 Google Cloud Platform-如何将图像文件上传到Google Cloud Storage Bucket? - Google Cloud Platform - How to upload image file into google cloud storage bucket? 使用PHP将文件上传到Google Cloud Storage Bucket - Upload files to Google Cloud Storage Bucket using PHP 如何使用php将文件上传到Google云存储中存储桶中的子文件夹 - how to upload file to subfolder in bucket in google cloud storage using php 使用PHP和Ajax将文件上传到Google Cloud Storage Bucket - Upload a file to Google Cloud Storage Bucket with PHP and Ajax 使用PHP将图像上传到Google Cloud Storage? - Upload an image to Google Cloud Storage with PHP? 将图片文件上传到Google云存储 - upload image file to google cloud storage 如何使用PHP将图像上传到谷歌云存储与GAE - how to upload a image to google cloud storage with GAE using php 使用PHP从Google Cloud Storage上传和检索图像 - Upload and Retrieve Image from Google Cloud Storage in PHP 是否可以仅使用 Authorization Bearer Token 和 Bucket 名称将文件上传到谷歌云存储? (PHP代码) - Is it possible to upload files to google cloud storage with just Authorization Bearer Token and Bucket name? (php code) 将 Google Cloud Storage 备份到另一个 Bucket - Backing up Google Cloud Storage to another Bucket
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM