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 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?
  • ¥15 关于#vue.js#的问题:修改用户信息功能图片无法回显,数据库中只存了一张图片(相关搜索:字符串)
  • ¥15 texstudio的问题,
  • ¥15 spaceclaim模型变灰色
  • ¥15 求一份华为esight平台V300R009C00SPC200这个型号的api接口文档
  • ¥15 字符串比较代码的漏洞
  • ¥15 欧拉系统opt目录空间使用100%
  • ¥15 ul做导航栏格式不对怎么改?