2015-11-04 39 views
0

我在服务器(gae)中创建数据,我想将其存储在Blobstore中。我看到了很多关于如何做到这一点的答案,给客户端一个BlobStore URL,但没有客户端或HTTP请求:它只是一个异步任务。服务器端上传到Blobstore - Java Google Appengine

  1. 那么我想我应该用createUploadUrl()的,而是给这个URL到客户端,从我的代码HTTP通过URL后我的数据给它取。这看起来很奇怪,是不是有另一个API?

  2. 假设我在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保存它,我不会从Blob存储得到它,即使我创造的BlobKey,或者是它的东西,可以工作,但我只是做错了什么?

1K感谢

回答

1

为什么你想将文件存储在Blob存储,而不是写,直接从GCS读它?

是的,您可以为存储在GCS中的文件创建BlobKey,并且可以在某些Blobstore API(例如fetchDataserve)中使用该密钥,但不幸的是不会。 一些blobstore API(如BlobstoreInputStream)取决于BlobInfo,并且在使用GCS客户端时不会创建。

+0

有很多原因可以想要。这就像问Blobstore有什么好处,对吧? :)但是如果你说我可以为GCS中的任何文件创建一个下载URL,那么这会减少一个好处。就我而言,这也是需求和遗留原因。我认为fetchData会给我我想要的,谢谢。关于我的问题1我想你确认我能做的唯一事情就是从我的服务器应用程序发送HTTP Post。 –

+0

是的,没有办法直接写入blobstore。现在已过时的文件api已被弃用(https://cloud.google.com/appengine/docs/java/googlecloudstorageclient/migrate)。 – ozarov

相关问题