Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert servlet schema to app-engine endpoint schema

Would the following conversion hold for converting from Java servlet to google app-engine cloud endpoint?

FROM

public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException { … }

TO

@ApiMethod(name = "save_blob_key", path = "save_blob_key" httpMethod = HttpMethod.POST)
public void saveBlobKey(HttpServletRequest req) throws IOException { … }

CONTEXT:

I am trying to use endpoint to process blobstore callback.

Ref: https://developers.google.com/appengine/docs/java/blobstore/overview#Complete_Sample_App

PROBLEM:

The big hickup here is that the following two lines seem to require the class HttpServletRequest and I don't know if I may pass it to endpoint.

BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
Map<String, List<BlobKey>> blobs = blobstoreService.getUploads(req);

EDIT:

I have been trying quite a lot of routes to solve this problem. My latest is combining blob servlet with endpoint api. Still I am not able to get the code to work. So the bounty goes to anyone who provides a solution or information that actually leads to a solution.

like image 495
learner Avatar asked Apr 27 '13 23:04

learner


1 Answers

You can't currently use Endpoints as a callback to the blobstore blobstoreService.createUploadUrl. See this related answer. There is an open feature request for supporting mediaUpload, which would likely provide similar functionality to what you want. Feel free to star it to show support and get automatic updates.

What I'd recommend would be one of two possible alternatives, depending on the amount of data you are trying to upload.

If you're uploading small amounts of blob data, that would fit in the datastore, use the ShortBlob (up to 500 bytes) or Blob (up to 1 MB) type in your Endpoints entity class. Endpoints will handle serialization on the backend and will expect (and send back) base64-encoded strings via the client libraries. This is a very simple, straightforward approach.

If you want to provide blobs larger than 1 MB, for now, use the Google Cloud Storage JSON API. This API uses the same client library as Endpoints, so you don't have to worry about bundling another library with your application. This page has an example of inserting a blob into Google Cloud Storage with the Java client library.

like image 186
Dan Holevoet Avatar answered Oct 12 '22 23:10

Dan Holevoet