Google Appengine Datastore Blobを使用して画像を保存していますが、代わりにBlobstoreを使用したいと思います。既存のすべてのBLOBをBlobstoreに移動する必要があります。GAE for Javaでそれを行うための最良の方法は何ですか?
2 に答える
0
Nick Johnsonが提案したように、MapReduceを使用して問題を解決しました。
プロジェクトを確認します。
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);
}
}
于 2012-05-21T16:02:54.863 に答える