I would like to updload and get pictures from my android application using the appengine Blobstore. I have some issue. I think that I didn't understand very well the process of the blobstore.
Here it's what I have done:
In my client side (Android) I just call an URL (api/pictures/upload/) and post my picture as an array of bytes (byte[]). I think that my client side is good.
In my server side (using appengine in java with Jersey) here is my webservice :
- Upload Web Service : (this function is called directly by android)
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response uploadImageBis(@Context HttpServletRequest req, @Context HttpServletResponse res) throws IOException{
BlobstoreService bs = BlobstoreServiceFactory.getBlobstoreService();
bs.createUploadUrl("/upload");
Map<String, List<BlobKey>> blobFields = bs.getUploads(req);
List<BlobKey> blobKeys = blobFields.entrySet().iterator().next().getValue();
if (blobKeys != null && !blobKeys.isEmpty()) {
BlobKey blobKey = blobKeys.get(0);
System.out.println("MY KEY: "+blobKey.getKeyString());
}
return null;
}
The line " BlobstoreService bs = BlobstoreServiceFactory.getBlobstoreService();
" create an error : Must be called from a blob upload callback request
But after a while it is persist (in the datastore or blobstore) and when I check my datastore there is a new tab created called : BlobUploadSession
Then when I tried to get the picture using the key from the console of google I have this mistake : Could not find blob: BlobKey:... I guess that maybe the picture is store in the dataStore instead of the blobstore??
But I think that I did something wrong in my Upload Web Service. If someone can help me and explain what is wrong it's will be great. Thx.