I have some simple code that handles the upload of a profile image (it's the callback after BlobstoreService has done its voodoo).
protected void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
BlobstoreService blobSvc = BlobstoreServiceFactory.getBlobstoreService();
Map<String, List<BlobKey>> blobs = blobSvc.getUploads(req);
List<BlobKey> blobKeys = blobs.get(UserSvc.fieldProfileImg);
String principalKey = req.getParameter(UserSvc.fieldPrincipalKey);
boolean failure = true;
if (null != blobKeys && blobKeys.size() > 0) {
Optional<Principal> princi = GaeDataUtil.getByWebKey(principalKey);
if (princi.isPresent()) {
log.info("Before adding BlobKey: " + princi.get());
princi.get().setProfileImgKey(blobKeys.get(0));
princi.get().setMiddleName("Saved"); // just to test if any other value will update
ofy().save().entity(princi.get()).now();
log.info("After adding BlobKey and saving: " + princi.get());
failure = false;
res.getWriter().print("SUCCESS");
} else {
log.warning("Failed to find Principal with web key: " + principalKey);
}
}
if (failure) {
res.getWriter().print("FAIL");
}
}
Everything works, except the re-saving of the retrieved entity.
Background Infomation
My own server-side code is submitting the profile image data to the BlobstoreService (let's not get into why that is so). The submission/upload works, am able to see it in the admin/Datastore of the devserver, I get the BlobKey I want, can even retrieve the Principal from the webKey, but can't seem to save the updated entity. No exceptions either.
Initially when I tried this I wasn't retrieving the BlobKey and I noticed that the Datastore would show two special entities: __BlobInfo__ and another one whose name I can't recall but it began and ended with __ (double underscore). After I flushed memcache, I could see only __BlobInfo__ entities, the other one was nowhere to be seen. I deleted the target\<appname>-1.0-SNAPSHOT\WEB-INF\appengine-generated\local_db.bin trying to reset the Datastore, but I still couldn't see any sign of the other special entity in the Datastore.
Is there a way to reset the Datastore and Blobstore on development server?
Environment:
- Development server
- Java 7
- Windows 7
- Objectify 5.1.7
ofy().save().entity(princi.get()).now()does not fail (The documentation ofnow()is "If the computation produced an exception, it will be thrown here.") but you don't see the update in the datastore viewer? You can reset your local env: at startup in the logs it says something about creating a sql file, delete that. - zapl