Package org.apache.commons.fileupload.servlet

Examples of org.apache.commons.fileupload.servlet.ServletFileUpload


            //
            // parse multipart request and extract the file
            //
            FileItemFactory factory = new DiskFileItemFactory(1048000, new File(System.getProperty("java.io.tmpdir")));
            ServletFileUpload upload = new ServletFileUpload(factory);
            upload.setSizeMax(-1);
            upload.setHeaderEncoding("UTF8");
            try {
                for (Iterator it = upload.parseRequest(request).iterator(); it.hasNext();) {
                    FileItem fi = (FileItem) it.next();
                    if (!fi.isFormField()) {
                        if (fi.getName() != null && fi.getName().length() > 0) {
                            tmpWar = new File(System.getProperty("java.io.tmpdir"), FilenameUtils.getName(fi.getName()));
                            fi.write(tmpWar);
View Full Code Here


    HttpServletRequest hRequest = (HttpServletRequest) servletReqest;
    // 构建带上传进度监视的文件工厂
    MonitoredDiskFileItemFactory factory = new MonitoredDiskFileItemFactory(
        new UploadListener(hRequest));
    // 初始化上传参数
    ServletFileUpload upload = new ServletFileUpload(factory);
    upload.setFileSizeMax(this.fileSizeMax);
    upload.setSizeMax(this.sizeMax);
    upload.setHeaderEncoding("UTF-8");

    Set<String> fileNames = new HashSet<String>();
    try {
      List<MonitoredDiskFileItem> items = upload.parseRequest(hRequest);
      long size;
      String fileName, extName;
      // 上传的路径
      File target = new File(this.isAbsolute ? this.uploadPath : hRequest
          .getSession().getServletContext().getRealPath(this.uploadPath));
View Full Code Here

      String charset) {
    // 构建带上传进度监视的文件工厂
    MonitoredDiskFileItemFactory factory = new MonitoredDiskFileItemFactory(
        new UploadListener(request));
    // 初始化上传参数
    ServletFileUpload upload = new ServletFileUpload(factory);
    upload.setFileSizeMax(this.fileSizeMax);
    upload.setSizeMax(this.sizeMax);
    upload.setHeaderEncoding(charset);

    try {
      List<FileItem> items = upload.parseRequest(request);
      for (FileItem item : items) {
        if (item.isFormField()) {
          try {
            params
                .put(item.getFieldName(), item
View Full Code Here

public class FileUploadWrapper extends HttpServletRequestWrapper {
 
  /** Constructor.  */
  public FileUploadWrapper(HttpServletRequest aRequest) throws IOException {
    super(aRequest);
    ServletFileUpload upload = new ServletFileUpload( new DiskFileItemFactory());
    try {
      List<FileItem> fileItems = upload.parseRequest(aRequest);
      convertToMaps(fileItems);
    }
    catch(FileUploadException ex){
      throw new IOException("Cannot parse underlying request: " + ex.toString());
    }
View Full Code Here

        uploadSize = (multipartUploadMaxSizeKB * 1024l * 1024l) + 512000l;
      }

      // Create a new file upload handler, use commons fileupload streaming
      // API to save files right to the tmp location
      ServletFileUpload uploadParser = new ServletFileUpload();
      uploadParser.setSizeMax(uploadSize);
      // Parse the request
      try {
        FileItemIterator iter = uploadParser.getItemIterator(ureq.getHttpReq());
        while (iter.hasNext()) {
          FileItemStream item = iter.next();
          String itemName = item.getFieldName();
          InputStream itemStream = item.openStream();
          if (item.isFormField()) {
View Full Code Here

    String message = null;
    Map<String, String> parameters = new HashMap<String, String>();
    List<FileItem> files = new ArrayList<FileItem>();
    try {
      if (request.getContentType().startsWith("multipart/form-data")) {
        ServletFileUpload upload = new ServletFileUpload();
        upload.setFileSizeMax(MAX_SIZE);
        upload.setHeaderEncoding("UTF-8");
        FileItemIterator iter;
        try {
          iter = upload.getItemIterator(request);
          InputStream stream = null;
          while (iter.hasNext()) {
            FileItemStream item = iter.next();
            stream = item.openStream();
            if (item.isFormField()) {
View Full Code Here

  @Override
  public void parseRequestParameters(Map<String, String> params,
      Map<String, com.bradmcevoy.http.FileItem> files) throws RequestParseException {
        try {
            if (isMultiPart()) {
                ServletFileUpload upload = new ServletFileUpload();
                List<FileItem> items = upload.parseRequest(request);
                parseQueryString(params);
                for (FileItem item : items) {
                    if (item.isFormField()) {
                        params.put(item.getFieldName(), item.getString());
                    } else {
View Full Code Here

    String comment = null;
    FileItem imageFileFormField = null;
    try
    {
      FileItemFactory factory = new DiskFileItemFactory();
      ServletFileUpload upload = new ServletFileUpload(factory);
      List<?> items = upload.parseRequest(request);
      Iterator<?> iter = items.iterator();
      while(iter.hasNext())
      {
          item = (FileItem)iter.next();
          if(item.getFieldName().equals("file"))
View Full Code Here

            File tmpDir = new File(tempDirectory);
            if (tmpDir.exists() && tmpDir.isDirectory()){
                factory.setRepository(tmpDir);
            }
        }
        ServletFileUpload upload = new ServletFileUpload(factory);
        if (maxFileSize > 0){
            upload.setFileSizeMax(maxFileSize);
        }
       
        Map<String,List<String>> tmpParams = new HashMap<String,List<String>>();
        Map<String,List<MultipartFile>> tmpFiles = new HashMap<String,List<MultipartFile>>();
       
        List<?> items = upload.parseRequest(request);
        for(Object itemObject: items){
            FileItem item = (FileItem)itemObject;
            if (item.isFormField()){
                List<String> list1 = tmpParams.get(item.getFieldName());
                if (list1 == null){
View Full Code Here

      File disk = null;
      FileItem item = null;
      FileItemFactory factory = new DiskFileItemFactory();
      Iterator iter = null;
      List items = null;
      ServletFileUpload upload = new ServletFileUpload( factory );
      ServletOutputStream out = null;
      try{
        items = upload.parseRequest( req );
        iter = items.iterator();
        res.setContentType( " text/xml");
        out = res.getOutputStream();
        out.println( " <response> " );
        while( iter.hasNext() ){
View Full Code Here

TOP

Related Classes of org.apache.commons.fileupload.servlet.ServletFileUpload

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.