0

Google Appengine Datastore Blobを使用して画像を保存していますが、代わりにBlobstoreを使用したいと思います。既存のすべてのBLOBをBlobstoreに移動する必要があります。GAE for Javaでそれを行うための最良の方法は何ですか?

4

2 に答える 2

2

私の知る限り、自動的な方法はありません。

次のことを行う必要があります。

  1. 既存のすべてのエンティティに対してクエリを実行します (エンティティが多数ある場合はカーソルを使用)。
  2. Blob データを Blobstore に書き込む
  3. エンティティを更新します。既存の blob プロパティを削除し、blobkey を使用して新しいプロパティを追加します。
于 2012-04-08T07:41:33.937 に答える
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 に答える