Java 解码使用文件系统API创建的文件
我使用文件系统API将图像上传到blobstore。文件已成功上载,我可以在相应的目录中看到blob 但是,我如何解码这些文件,以便在发送回客户机或使用BlobstoreAPI检索时,能够获得图像?现在/blobstore/writable:xxx对我没有用处,因为当我在Java 解码使用文件系统API创建的文件,java,google-app-engine,Java,Google App Engine,我使用文件系统API将图像上传到blobstore。文件已成功上载,我可以在相应的目录中看到blob 但是,我如何解码这些文件,以便在发送回客户机或使用BlobstoreAPI检索时,能够获得图像?现在/blobstore/writable:xxx对我没有用处,因为当我在中包装路径时,它不会给我一个图像。有几个选项- 用于创建图像的URL,然后将该URL作为响应的一部分返回。将此URL存储在数据存储中,因为同一blob的URL不会更改。这还允许您动态调整和裁剪正在服务的图像。URL是公共的,因此
中包装路径时,它不会给我一个图像。有几个选项-
我用这个把它修好了:
FileService fileService = FileServiceFactory.getFileService();
AppEngineFile writableFile = fileService.createNewBlobFile(request.getParameter("qqfile"));
FileWriteChannel writeChannel = null;
try {
byte[] buffer = new byte[4096]; // 4MB
lock = true;
writeChannel = fileService.openWriteChannel(writableFile, lock);
// increase the buffer size as you are reading from the
// input stream. Read the input stream into buffer
for (int n; (n = stream.read(buffer)) != -1; ){
writeChannel.write(ByteBuffer.wrap(buffer));
}
} finally {
writeChannel.closeFinally();
}
BlobKey blobKey = fileService.getBlobKey(writableFile);
ImagesService imagesService = ImagesServiceFactory.getImagesService();
// produces something like http://localhost:8888/_ah/img/SU52WMsoCRP3kqAvQqVW3g
String imageUrl = imagesService.getServingUrl(blobKey);
在1上,我不打算将图像存储在blobstore中。相反,我使用的是文件系统API。但这样做时我是个例外:
java.lang.IllegalArgumentException:无法读取图像
。你知道我可能做错了什么吗?仅供参考,文件系统API在blobstore或google存储中存储Blob。您需要从存储的对象生成blobkey。