我有一些文件上传代码可以在appspot.com上运行,但不能在本地Java dev服务器上运行。
我将通过以下网址上传到Google云端存储空间
String bucketName = AppIdentityServiceFactory.getAppIdentityService().getDefaultGcsBucketName();
String uploadUrl = blobstoreService.createUploadUrl(
successUrl,
UploadOptions.Builder.withGoogleStorageBucketName(bucketName)
);
在我的上传处理程序(由“successUrl”指向)中,我尝试从GCS存储桶读取新上传的blob。这是这样做的:
BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
Map<String, List<BlobKey>> uploads = blobstoreService.getUploads(req);
Map<String, List<FileInfo>> files = blobstoreService.getFileInfos(req);
...
// use the FileInfo instance to do fileInfo.getGsObjectName()
...
GcsInputChannel readChannel = gcsService.openPrefetchingReadChannel(gcsFilename, 0, 1024 * 1024);
InputStream is = Channels.newInputStream(readChannel));
在实际的appengine实例上,fileInfo.getGsObjectName()返回一个这样的工作路径:
/gs/myapp.appspot.com/L2F..LongIDHere...YmJV
工作并可以读取,但是,在本地开发服务器上,我得到类似的东西:
/gs/app_default_bucket/fake-encoded_gs_key:YXB...LongIdHere...6de
在尝试使用相同的代码读取时抛出FileNotFoundException,该代码适用于appEngine: - (