Google App Engine Blobstore and Restlet - "Must be called from a blob upload callback request"
Asked Answered
W

1

7

Error

Caused by: java.lang.IllegalStateException: Must be called from a blob upload callback request. at com.google.appengine.api.blobstore.BlobstoreServiceImpl.getUploads(BlobstoreServiceImpl.java:169)

Code

public class UserUploadProfilePictureResource extends ServerResource {

    @Post
    public void handleBlobstoreUpload(Representation entity) {

        Representation rep =null;

        if (entity !=null) {

            if (MediaType.MULTIPART_FORM_DATA.equals(entity.getMediaType(), true)) {
                Request restletRequest = getRequest();
                HttpServletRequest servletRequest = ServletUtils.getRequest(restletRequest);

                BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();

                Map<String, List<BlobKey>> blobs = blobstoreService.getUploads(servletRequest);

possible Solution (but what I don't want)

First. I don't want to call a second HttpServlet.

Second. Regarding to this posts there is the solution to write manually the file:

Google says following:

Deprecated: The Files API feature used here to write files to Blobstore is going to be removed at some time in the future, in favor of writing files to Google Cloud Storage and using Blobstore to serve them.

possible Solution2 (but only a concept for a workaround)

http://www.cloudave.com/1055/the-new-google-app-engine-blobstore-api-first-thoughts/

Bret Slatkin notes that when the API manufactures the POST URL to be used for uploading the files, it creates a unique one-time URL which which mitigates any potential sniffing.

This fits perfectly for the scenario when you’re rendering a web form to be submitted by the user. But, it makes things harder if you’re trying to provide a REST API that allows uploading files (think of something like TwitPic for example). In this case you’ll have to write your own render that simulates what a web form would do (get the files, create random POST URL, call it, …)

Question

What is my best approach to store images in the google app engine? Is there a better way than the blobstore? How can I store images in the blobstore?

Willams answered 4/8, 2013 at 11:5 Comment(3)
You have left out some of your code. Where are you calling blobstoreService.createUploadUrl(path) If you are not calling that function, that is the problem.Pyriphlegethon
@Pyriphlegethon I tried to call it before blobstoreService.getUploads. But that changed nothing in the behaviorWillams
Did you solve this problem? I've the same issue =(Bluepencil
C
3

I think your best and will be officially supported choice is the Google Cloud Storage Client Library, https://developers.google.com/appengine/docs/java/googlecloudstorageclient/ It's looking that way that they will not support writing to blobstore programmatically anymore probably to promote usage of cloud storage over blobstore. Image and blobstore api works on GCS for creating and storing blobstore keys and generating images url/resizing etc.

The other unofficial way that I haven't looked much into is copying the Files Api source and maintaining it yourself, it's probably using rpc calls that won't go away or always available but I don't know exactly.

Conciseness answered 8/8, 2013 at 21:47 Comment(2)
sorry but that is no solution. this is another technology... Then you can advise amazon s3 too. The blobstore is cheaper and enough for my workflow and that's why I want to use it.Willams
this other technology is actually tightly integrated with blobtstores api and app engine. Also pricing is cheaper than s3 and blobstore itself just by passing the free 5GB limit you will be paying more than blobstore and cloudstorage and it has a built in cdn like capabilities so it auto cache on edge servers.Conciseness

© 2022 - 2024 — McMap. All rights reserved.