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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With