duanru6816 2014-10-15 00:25
浏览 97
已采纳

Appengine Cloud Storage上传图像并存储在存储中

I have a problem. any help is welcome.

I am developing a solution that need to use google apis like cloud storage, Drive, etc.

In the clasic profile page I have to upload picture profile. then I use a angularjs to post data to my appengine/php/yii

formPHP:

`

<?php
require_once 'google/appengine/api/cloud_storage/CloudStorageTools.php';
use google\appengine\api\cloud_storage\CloudStorageTools;
$options = [ 'gs_bucket_name' => 'seektrabajo' ];
$upload_url = CloudStorageTools::createUploadUrl('/perfiles/subirFotoPerfil', $options);
?>
<input type="file" name="file" 
       nv-file-select="uploader.uploadAll()" 
       uploader="uploader"   />

`

and when submit send data to google and google to yii ajax service:

`

public function actionSubirFotoPerfil(){
     $answer = array('answer'=>'Incompleted','serverFile'=>'sinfoto.png');
     if(!empty( $_FILES )){
         $filename = $_FILES['file']['name'];
         $gs_name =  $_FILES['file']['tmp_name'];
         move_uploaded_file($gs_name, 'gs://seektrabajo/'.$filename);
         $answer = array( 'answer' => 'File transfer completed','serverFile' => $filename);
     }
     echo json_encode( $answer );
     Yii::app()->end();
 }

`

the problem is that never save the file uploaded to my bucket on cloud storage. this not work for development/local mode and either appengine deployed. in appengine land, I get this error:

I just get permision to bucket:

gsutil acl ch -u user@gmail.com:FULL_CONTROL gs://seektrabajo

the user@gmail.com y get from my google console/ apis-autentications/ Email

![web browser console error][1]

http://i.stack.imgur.com/noKnh.png

Somebody have an idea? Thanks.

  • 写回答

1条回答 默认 最新

  • douxianglu4370 2014-12-20 22:44
    关注

    Why are you uploading the files to a static handler then uploading them to GCS? Use createUploadUrl() to template the <form> you serve. Provide a callback URL on your own app to the function and once the file is uploaded, a request will go to your app with the rest of the parameters of the form, the metadata of the file, etc...

    With the pattern you are using, there is not only the headache of trying to figure out how to stream the data correctly, there's the simple fact that you're handling all that read/write on your instance, which is surely not a good idea if you intend to use this in production code where you pay for the used resources.

    In short, there's no reason to use this pattern. In a traditional web app, you would post the file form to your own server on a route and do like you are in your example code (minus forwarding to GCS), but with App Engine you need to think a little different than the traditional ways of web development on a single VM you purchase and host a PHP runtime on.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面