convert servlet schema to app-engine endpoint schema
Asked Answered
G

1

4

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.

Gooding answered 27/4, 2013 at 23:21 Comment(1)
It has been many years now, were you able to find a solution?Transudation
T
3

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.

Thorley answered 30/4, 2013 at 21:21 Comment(1)
The issue about Endpoints support for mediaUpload is now almost 2.5 years old. Nothing has happened. This is typical for AppEngine issues. I wonder when Google will get rid of AppEngine in a spring or autumn cleaning?Scintillate

© 2022 - 2024 — McMap. All rights reserved.