2012-12-21 31 views
1

我试图从GAE中的'上载成功'处理程序获取文件内容。文件被上传到网址:无法读取上传成功处理程序中的Google Storage Cloud文件

blobstoreService.createUploadUrl("/onupload", uploadOptions)); 

所以,在/onupload,我做这样的:

BlobKey myFile = context.getRequestBlobs().get("myFile").get(0); 

,然后我尝试:

InputStream is = new BlobstoreInputStream(myFile); 
// .. read the stream 

失败并com.google.appengine.api.blobstore.BlobstoreInputStream$BlobstoreIOException: BlobstoreInputStream received an invalid blob key: =?ISO-8859-1?Q?AMIfv96J=2DsyIbhm5=5FET?=

and

FileReadChannel ch = fileService.openReadChannel(myFile, false); 

java.io.IOException 
    at com.google.appengine.api.files.FileServiceImpl.translateException(FileServiceImpl.java:615) 
    at com.google.appengine.api.files.FileServiceImpl.makeSyncCall(FileServiceImpl.java:588) 
    at com.google.appengine.api.files.FileServiceImpl.open(FileServiceImpl.java:521) 
    at com.google.appengine.api.files.FileServiceImpl.openForRead(FileServiceImpl.java:481) 
    at com.google.appengine.api.files.FileServiceImpl.openForRead(FileServiceImpl.java:473) 
    at com.google.appengine.api.files.FileServiceImpl.openReadChannel(FileServiceImpl.java:197) 

未能什么我做错了任何想法,并有可能在所有读取上传投手文件的内容?

请注意,对于blobstore FS(非GS)它工作正常。

回答

0

我认为你正试图从谷歌云存储中读取文件。 你见过文档示例[1]吗?

特别是这部分:

/ At this point, the file is visible in App Engine as: 
// "/gs/BUCKETNAME/FILENAME" 
// and to anybody on the Internet through Cloud Storage as: 
// (http://storage.googleapis.com/BUCKETNAME/FILENAME) 
// We can now read the file through the API: 
String filename = "/gs/" + BUCKETNAME + "/" + FILENAME; 
AppEngineFile readableFile = new AppEngineFile(filename); 
FileReadChannel readChannel = 
    fileService.openReadChannel(readableFile, false); 
// Again, different standard Java ways of reading from the channel. 
BufferedReader reader = 
     new BufferedReader(Channels.newReader(readChannel, "UTF8")); 
String line = reader.readLine(); 
resp.getWriter().println("READ:" + line); 

// line = "The woods are lovely, dark, and deep." 
readChannel.close(); 

[1] https://developers.google.com/appengine/docs/java/googlestorage/overview#Complete_Sample_App

+0

好,好东西,但我没有文件名由于GS/GAE(错误的http://代码。 google.com/p/googleappengine/issues/detail?id=8337)并拥有blob密钥(如问题所示)我无法创建读取频道... – tuxSlayer

+0

如果您想上传文件,请勿使用Blobstore服务。您可以使用[Apache Commons FileUpload](https://developers.google.com/appengine/kb/java#fileforms)并直接写入GS(不含Blobstore)。 – Eich

+0

这将不适用于大斑点 –

相关问题