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:
- how to get uploaded file as blobs in servlet using google app engine
- Upload an image to google app engine blobstore with java programmatically
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?
blobstoreService.getUploads
. But that changed nothing in the behavior – Willams