Package com.dotcms.repackage.org.apache.commons.fileupload

Examples of com.dotcms.repackage.org.apache.commons.fileupload.FileItem


        throw new Exception("Could not upload File. Invalid User");
      }


      for (Iterator i = items.iterator(); i.hasNext();) {
        FileItem fileItem = (FileItem) i.next();

        if (!fileItem.isFormField()) {


          // *************************************************
          // This is where you would process the uploaded file
          // *************************************************

          if(fileItem.getSize() == 0)
            isEmptyFile = true;

          if (fileItem.getName().contains(File.separator)) {
            fileName = fileItem.getName().substring(
                fileItem.getName().lastIndexOf(File.separator) + 1);
          } else {
            fileName = fileItem.getName();
          }
          fileName = ContentletUtil.sanitizeFileName(fileName);

          File tempUserFolder = new File(APILocator.getFileAPI().getRealAssetPathTmpBinary() + File.separator + userId +
              File.separator + fieldName);

          if(!isValidPath(tempUserFolder.getCanonicalPath())) {
            throw new IOException("Invalid fileName or Path");
          }

          if (!tempUserFolder.exists())
            tempUserFolder.mkdirs();
          File dest=new File(tempUserFolder.getAbsolutePath() + File.separator + fileName);
          if(dest.exists())
            dest.delete();
          fileItem.write(dest);
          fileItem.delete();
        }
      }

      if(isEmptyFile)
        fileName = "";
View Full Code Here

TOP

Related Classes of com.dotcms.repackage.org.apache.commons.fileupload.FileItem

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.