我使用Google Appengine Datastore Blob存储图片,但我想使用Blobstore。我需要将所有现有的blob移动到Blobstore。 使用GAE for Java做到这一点的最佳方法是什么?
答案 0 :(得分:2)
AFAIK没有自动方式。
您需要:
答案 1 :(得分:0)
我使用MapReduce解决了这个问题,正如Nick Johnson所说:
检查项目:
http://code.google.com/p/appengine-mapreduce/
Ikai Lan的精彩教程:
http://ikaisays.com/2010/07/09/using-the-java-mapper-framework-for-app-engine/
这就是map方法的样子:
@Override
public void map(Key key, Entity value, Context context) {
log.info("Mapping key: " + key);
try {
Entity picture = value;
if (!picture.hasProperty("blobKey") || picture.getProperty("blobKey") == null) {
String fileName = (String) picture.getProperty("fileName");
String contentType = (String) picture.getProperty("contentType");
Blob image = (Blob) picture.getProperty("image");
if (contentType != null && image != null) {
AppEngineFile file = fileService.createNewBlobFile(contentType,fileName);
FileWriteChannel writeChannel = fileService.openWriteChannel(file, true);
writeChannel.write(ByteBuffer.wrap(image.getBytes()));
writeChannel.closeFinally();
BlobKey blobKey = fileService.getBlobKey(file);
picture.setProperty("blobKey",blobKey);
datastore.put(picture);
}
else {
log.log(Level.SEVERE, "Mapping key: " + key + "failed - null contentType or image.");
}
}
} catch (Exception e) {
log.log(Level.SEVERE, "Mapping key: " + key, e);
}
}