GAE Blob Store获取文件大小

时间:2013-02-25 20:30:48

标签: java google-app-engine blobstore google-cloud-storage

我尝试用Java从Google App Engine中获取存储在Google云端存储中的文件大小,

我试过了:

FileService fileService = FileServiceFactory.getFileService();
AppEngineFile appEngineFile = fileService.getBlobFile(new BlobKey("blob key"));
int size = (int) fileService.stat(appEngineFile).getLength().longValue();

但它正在返回0

1 个答案:

答案 0 :(得分:2)

您必须使用BlobInfo.getSize()

BlobInfoFactory blobInfoFactory = new BlobInfoFactory();
BlobInfo blobInfo = blobInfoFactory.loadBlobInfo(new BlobKey("blob key"))
Long blobSize = blobInfo.getSize();