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

我尝试了这个:

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

但它返回0

最佳答案

您必须使用 BlobInfo.getSize() :

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

07-24 09:51