0
我正在开发一个项目,该项目使用内容类型“application/octet-stream”上载一些二进制数据,并且需要将其保存在BLOB列Oracle数据库。JSP上传内容类型为“application/octet-stream”的文件
我可以使用Commons fileupload吗?
这个任何示例代码?我只能找到内容类型为“multipart/form-data”的代码。
我正在开发一个项目,该项目使用内容类型“application/octet-stream”上载一些二进制数据,并且需要将其保存在BLOB列Oracle数据库。JSP上传内容类型为“application/octet-stream”的文件
我可以使用Commons fileupload吗?
这个任何示例代码?我只能找到内容类型为“multipart/form-data”的代码。
private byte[] getByteArrayFromUploadFile(HttpServletRequest request)throws Exception{
ServletFileUpload upload = new ServletFileUpload();
// Parse the request
FileItemIterator iter = null;
try{
iter = upload.getItemIterator(request);
}catch (Exception e) {
System.out.println("Error occured during getting iterator");
}
byte[] readBytes = null;
while (iter.hasNext()) {
FileItemStream item = null;
try{
item = iter.next();
}catch (Exception e) {
System.out.println("Error occured during Iteration");
}
String name = item.getFieldName();
if (!item.isFormField()) {
BufferedInputStream stream = new BufferedInputStream(item.openStream());
readBytes= new byte[stream.available()];
System.out.println("total Number of Bytes:"+ readBytes.length);
stream.read(readBytes);
}
}
return readBytes;
}
我试过这个,它似乎不适用于类型“application/octet-stream”。 – JayPea 2012-06-20 23:25:29