将文件上传到AppEngine Blobstore [英] File upload to AppEngine Blobstore

查看:87
本文介绍了将文件上传到AppEngine Blobstore的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

遵循此 blobstore文档了解如何上传到Blobstore。它显示通过JSP + Servlet方法上传。



由于我的应用程序基于GWT,我需要修改GWT RPC(而不是JSP)。



因此,在我的应用RPC服务实现中:

  public class MyServiceImpl extends RemoteServiceServlet implements 
MyService {

public String getUploadUrl(){
BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
return blobstoreService.createUploadUrl(/ upload)
}
}

这是正确的方法还是有其他方法可以正确执行?虽然我没有尝试过这段代码。



上传的二进制文件的范围从字节到最大2MB。

blobstore文档,了解如何上传到Blobstore。它显示通过JSP + Servlet方法上传。



由于我的应用程序基于GWT,我需要修改GWT RPC(而不是JSP)。



因此,在我的应用RPC服务实现中:

  public class MyServiceImpl extends RemoteServiceServlet implements 
MyService {

public String getUploadUrl(){
BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
return blobstoreService.createUploadUrl(/ upload)
}
}

这是正确的方法还是有其他方法可以正确执行?虽然我没有尝试过这段代码。



上传的二进制文件的范围从字节到2MB,最大值为

当我试用此代码时,这是服务器端控制台日志:

  2012年5月7日上午6:35:53 com.google.appengine.tools .development.LocalResourceFileServlet doGet 
警告:找不到找到的文件:/crossdomain.xml

然后在客户端GWT.log Rpc能够生成一个URL,但它不起作用:

  [INFO] [blobrpc ]  - 成功获取上传网址:http://127.0.0.1:8888/_ah/upload/aglub19hcHBfaWRyGwsSFV9fQmxvYlVwbG9hZFNlc3Npb25fXxgDDA 


解决方案

createUploadUrl()创建一个Url,需要一个带有Content-type头部的HTTP POST multipart /数据

如果您想使用GWT-RPC,则需要使用 Blobstore FileService API 在服务器端创建文件。


Following this blobstore document on how to upload to the Blobstore. It shows uploading through JSP + Servlet approach.

Since my app is based on GWT, I need to adapt the for GWT RPC (instead of JSP).

So in my app RPC service implementation:

public class MyServiceImpl extends RemoteServiceServlet implements
    MyService {

  public String getUploadUrl() {
    BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
    return blobstoreService.createUploadUrl("/upload")
  }
}

Is this the right approach or is there any other way to do it properly? I haven't tried this code though.

The binary that will be uploaded range from bytes to 2MB at max.

Following this blobstore document on how to upload to the Blobstore. It shows uploading through JSP + Servlet approach.

Since my app is based on GWT, I need to adapt the for GWT RPC (instead of JSP).

So in my app RPC service implementation:

public class MyServiceImpl extends RemoteServiceServlet implements
    MyService {

  public String getUploadUrl() {
    BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
    return blobstoreService.createUploadUrl("/upload")
  }
}

Is this the right approach or is there any other way to do it properly? I haven't tried this code though.

The binary that will be uploaded range from bytes to 2MB at max.

When I tried out this code, this is the server side console log:

May 07, 2012 6:35:53 AM com.google.appengine.tools.development.LocalResourceFileServlet doGet
WARNING: No file found for: /crossdomain.xml

Then on the client side GWT.log the Rpc was able to generate a URL however it does not work:

[INFO] [blobrpc] - Success fetch upload url: http://127.0.0.1:8888/_ah/upload/aglub19hcHBfaWRyGwsSFV9fQmxvYlVwbG9hZFNlc3Npb25fXxgDDA

解决方案

createUploadUrl() creates a Url that expects a HTTP POST with Content-type header multipart/form-data.

If you want to use GWT-RPC than you need to use Blobstore FileService API to create file on server side.

这篇关于将文件上传到AppEngine Blobstore的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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