commons-fileupload源码分析
来源:互联网 发布:袁菱照片疯传网络 编辑:程序博客网 时间:2024/06/05 11:23
public void doPost(HttpServletRequest req, HttpServletResponse res) { DiskFileItemFactory factory = new DiskFileItemFactory(); // maximum size that will be stored in memory factory.setSizeThreshold(4096); // the location for saving data that is larger than getSizeThreshold() factory.setRepository(new File("/tmp")); ServletFileUpload upload = new ServletFileUpload(factory); // maximum size before a FileUploadException will be thrown upload.setSizeMax(1000000); List fileItems = upload.parseRequest(req); // assume we know there are two files. The first file is a small // text file, the second is unknown and is written to a file on // the server Iterator i = fileItems.iterator(); String comment = ((FileItem)i.next()).getString(); FileItem fi = (FileItem)i.next(); // filename on the client String fileName = fi.getName(); // save comment and filename to database ... // write the file fi.write(new File("/www/uploads/", fileName)); }
以上代码为apache官网的一段commons-fileupload的demo。其中主要分为两个部分
1、创建DiskFileItemFactory
2、创建SerletFileUpload
(1)DiskFileItemFactory实现了FileItemFactory接口createItem,在里面指定了默认的阀值。同时声明一个FileCleaningTracker去跟踪是否超过阀值。
0 0
- commons-fileupload源码分析
- commons-fileupload 核心API 分析
- commons-fileupload
- Commons FileUpload
- commons-fileupload
- commons-fileupload
- commons fileupload
- Commons-FileUpload
- 利用commons-fileupload实现文件的上传(源码)
- 利用commons-fileupload实现文件的上传(源码)
- 利用commons-fileupload实现文件的上传(源码)
- struts源码分析:commons-logging
- Apache Commons-Pool 源码分析
- commons-pool源码分析总结
- Apache Commons Pool2 源码分析
- Apache Commons-Logging 源码分析
- commons-fileupload user guide
- Smartupload和commons-fileupload
- OGRE的主要渲染流程
- GPU渲染3D图形的粗略步骤,虽然粗略但也是通用步骤
- 1021. 个位数统计 (15)
- java实现内部类
- Spring MVC之@RequestParam @RequestBody @RequestHeader 等详解
- commons-fileupload源码分析
- OGRE 使用技巧总结
- UI - SaveFile
- 使用git查阅Android M中Doze相关代码
- NYOJ——13 Fibonacci数
- 文章标题
- java.util.Properties类 学习笔记1
- shellhomework
- iOS开发控件基础