1

我正在尝试从 GAE 中的“上传成功”处理程序中获取文件内容。文件上传到url:

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),它运行良好。

4

1 回答 1

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

于 2012-12-21T12:26:46.517 回答