【发布时间】:2015-11-04 01:01:52
【问题描述】:
我在服务器 (gae) 中创建数据,我想将其存储在 Blobstore 中。我看到了很多关于如何向客户端提供 BlobStore URL 的答案,但是没有客户端或 HTTP 请求:它只是一个异步任务。
然后我想我应该使用 createUploadUrl(),而不是将此 URL 提供给客户端,而是从我的代码 HTTP 通过 URL Fetch 将我的数据发布到它。这看起来很奇怪,难道没有其他 API 吗?
假设我想要在 Blobstore 中的文件已经存储在我的 GCS 默认存储桶中。我可以使用 gcs 位置“/gs/bucketname/file”告诉 Blobstore 吗?我试过了
GcsFilename filename = new GcsFilename(bucketName, fileId);
String gcsKey = "/gs/" + bucketName + "/" + filename.getObjectName();
BlobKey blobKey = blobstoreService.createGsBlobKey(gcsKey);
GcsOutputChannel outputChannel = gcsService.createOrReplace(filename, GcsFileOptions.getDefaultInstance());
ObjectOutputStream oout = new ObjectOutputStream(Channels.newOutputStream(outputChannel));
oout.writeObject(myDataObjectToPersist);
oout.close();
// ...at some other point I have checked the file is correctly stored in
// GCS and I can fetch it using /gs/bucket/fileId
// but it doesn't seem to be in Blobstore, so when
InputStream stream = new BlobstoreInputStream(new BlobKey(blobKey.keyString))
// ... this gives a BlobstoreInputStream$BlobstoreIOException: BlobstoreInputStream received an invalid blob key...
这在概念上是错误的吗?例如,如果我使用 GcsOutputChannel 保存它,即使我创建了 BlobKey,我也不会从 Blobstore 获取它,还是它可以工作但我做错了什么?
1K 谢谢
【问题讨论】:
标签: java google-app-engine google-cloud-storage blobstore