quarks
quarks

Reputation: 35276

File upload to AppEngine Blobstore

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

Upvotes: 3

Views: 1866

Answers (2)

Dau Van Thang
Dau Van Thang

Reputation: 21

If we were to post a file to that URL, it would be saved in blobstore. Note however that the default URL for the local development web server is http://127.0.0.1:8888/ while the URL generated by blobstore is http://:8888/. This will cause problems later on, as for security reasons Plupload won't be able to POST files to another domain. This only happens with the local development server, the published app will have only one URL. Fix it by editing the Run Configurations in Eclipse, add -bindAddress to the arguments. This will cause the local development server to host the web app on http://:8888/ instead. You might need to allow in the GWT browser plugin for it to load the app after this change.

Multiple file upload using GWT and AppEngine Blobstore?

Upvotes: 0

Peter Knego
Peter Knego

Reputation: 80330

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.

Upvotes: 2

Related Questions