我可以使用以下代码将文件作为 blob 上传,
<form action="<%= blobstoreService.createUploadUrl("/upload") %>" method="post" enctype="multipart/form-data">
<input type="file" name="myFile">
<input type="submit" value="Submit">
</form>
但在我的情况下,我使用Apache Common File Uploader上传文件。所以我的表单动作如下,
<form action="/upload" method="post" enctype="multipart/form-data">
现在在我的 servlet 中将文件作为 InputStream 获取。如果我想将文件转换为同一个 servlet 文件中的 blob,我该如何转换它。请给我一个想法。
更新
我尝试使用Writing files to blob store 我的代码如下,
FileService fileService = FileServiceFactory.getFileService();
AppEngineFile file = fileService.createNewBlobFile(mime,fileName);
boolean lock = true;
FileWriteChannel writeChannel = fileService.openWriteChannel(file, lock);
byte[] b1 = new byte[BUFFER_SIZE];
int readBytes1 = is.read(b1, 0, BUFFER_SIZE);
while (readBytes1 != -1) {
writeChannel.write(ByteBuffer.wrap(b1, 0, BUFFER_SIZE));}
现在我可以在应用引擎中上传文件,它存储 blob 值,但我无法查看 blob 值。当我使用<%= blobstoreService.createUploadUrl("/upload") %>
这一行时,我的应用程序引擎向我显示“查看 Blob”选项,但现在它不存在。此外,当我使用 Blob 列表查看文件时,它没有显示并显示“0”字节。我认为它只存储 blob 密钥而不是文件。请给我一个解决它的想法。