How can i recover Blobs after migration to HRD

2020-08-05 10:01发布

问题:

I just migrated to HRD and now its telling me i cant access my own blobs...

Uncaught exception from servlet
java.lang.SecurityException: This application does not have access to that blob.
at com.google.appengine.api.blobstore.BlobstoreServiceImpl.fetchData(BlobstoreServiceImpl.java:200)
at com.droidastic.telljokes.server.servlet.ServeBlobsServlet.checkBlobKeyExists(ServeBlobsServlet.java:100)
at com.droidastic.telljokes.server.servlet.ServeBlobsServlet.doGet(ServeBlobsServlet.java:64)

I stored the keys as a string inside the datastore entities and then i create them like this:

BlobKey key = new BlobKey(this.params.blobKey); 

How can i recover the blobs?

回答1:

I found a solution:

public String getMigratedBlobKey(String oldKey) {
  String migrationEntityKey = "__BlobMigration__";
  Key createKey = KeyFactory.createKey(migrationEntityKey, oldKey);
  Entity migrationEntity = datastore.get(createKey);
  BlobKey newKey = (BlobKey) migrationEntity.getProperty("new_blob_key");
  return newKey.getKeyString();
}

"__BlobMigration__" and "new_blob_key" are GAE constants.