【发布时间】:2012-08-17 10:08:21
【问题描述】:
我正在尝试保存并在 GoogleAppEngine 上提供 blob。
// Save the data as a blob
final FileService fileService = FileServiceFactory.getFileService();
final AppEngineFile file = fileService.createNewBlobFile("application/zip", "nameOfSavedFile");
final FileWriteChannel writeChannel = fileService.openWriteChannel(file, true);
writeChannel.write(ByteBuffer.wrap(data));
writeChannel.closeFinally();
// Load the blob data
Query query = new Query("__BlobInfo__");
query.addFilter("filename", FilterOperator.EQUAL, "nameOfSavedFile");
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
PreparedQuery pq = datastore.prepare(query);
List<Entity> entList = pq.asList(FetchOptions.Builder.withLimit(1));
String blobKeyString = entList.get(0).getKey().getName();
BlobstoreService blobStoreService = BlobstoreServiceFactory.getBlobstoreService();
BlobKey blobKeyLoaded = new BlobKey(blobKeyString);
blobStoreService.serve(blobKeyLoaded,response);
如果我运行上面的代码,它似乎可以工作。但是,当我再次运行相同的代码以用同名的新文件覆盖现有文件时,它只会为旧文件提供服务。
谁能解释一下如何用新文件覆盖旧文件?
谢谢!
【问题讨论】:
标签: java google-app-engine servlets blobstore