2012-12-21 32 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

這將不適用於大斑點 –

相關問題