我正在使用下面显示的代码将一个多部分文件上传到 Google 应用引擎。在 apache commons 文件上传器的帮助下,我成功地将文件上传到 Google 应用引擎。我想验证文件大小是否为 0 字节。为此,我验证了 Google 应用引擎和 apache 公共文件上传器以检查文件大小,但我失败了。我们有什么方法可以找到文件大小。请给我一个想法。
我的小服务程序
ServletFileUpload upload = new ServletFileUpload();
FileItemIterator iter;
iter = upload.getItemIterator(request);
while (iter.hasNext()) {
item = iter.next();
String fileName = item.getName();
String fieldName = item.getFieldName();
if (item.isFormField()) {
String fieldValue = Streams.asString(item.openStream());
}
InputStream is1 = item.openStream();
try {
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;
while ((readBytes1 = is1.read(b1)) != -1) {
writeChannel.write(ByteBuffer.wrap(b1, 0, readBytes1));
}
writeChannel.closeFinally();