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 = "";