我正在尝试从GAE中的“上传成功”处理程序获取文件内容。文件上传到网址:
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?=
和
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 :(得分:0)
我认为您正在尝试从Google云存储中读取文件。 你在文档上看到了例子[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