This code uploads a file to the Content manager(FileNet).
import java.io.File; import java.io.FileWriter; import java.io.PrintWriter; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.Hashtable; import java.util.Iterator; import java.util.List; import org.apache.commons.fileupload.FileItem; import org.apache.commons.fileupload.FileUploadException; import org.apache.commons.fileupload.disk.DiskFileItemFactory; import org.apache.commons.fileupload.servlet.ServletFileUpload; import java.io.BufferedInputStream; import java.io.IOException; import java.io.InputStream; import java.net.URL; public class FileUpLoad_Sample { File outFile = null; String fileName=null; int flag = 0; public IDataCapsule executeService(IDataCapsule dc) throws ActionException { String methodName = "ClaimInsertexecuteService"; IDataCapsule reqDC = InputDCHelper.getRequestDataCapsule(dc); ClaimInsertAF pf = new ClaimInsertAF(); pf = (ClaimInsertAF) reqDC.getObject(FWConstants.ACTION_FORM); HttpServletRequest req = (HttpServletRequest) pf.getReq(); try { XMLReader xmlRdr = new XMLReader(); FileRd f = new FileRd(); System.out.println(f.printData("IIP_Config.xml")); Hashtable details = xmlRdr.parseXML(new File(f.printData("IIP_Config.xml"))); HttpSession session = req.getSession(false); System.out.println("1"); if (ServletFileUpload.isMultipartContent(req)) { ServletFileUpload sFup = new ServletFileUpload(new DiskFileItemFactory()); try { List fileItemList = sFup.parseRequest(req); Iterator it = fileItemList.iterator(); while (it.hasNext()) { FileItem fItem = (FileItem) it.next(); if (fItem.isFormField()) { //This is used for other form elements like textboxes,DropDown etc., String fname = fItem.getFieldName().trim(); String fvalue = fItem.getString(); session.setAttribute(fname, fvalue); } else { fileName = fItem.getName(); if(fileName!="") { fileName = fileName.substring( fileName.lastIndexOf("\") + 1); outFile = new File(fileName); outFile.createNewFile(); fItem.write(outFile); flag = 1; } } } } catch (FileUploadException e) { //Write error reporting code! e.printStackTrace(); } catch (Exception e) { //Write error reporting code! e.printStackTrace(); } } else { //Write error reporting code! } if (flag == 1) { AddDocument add_filenet = new AddDocument(); System.out.println(outFile.getAbsolutePath()); String doc_id = add_filenet.insertClaims( fileName, outFile.getAbsolutePath(), claim_no); System.out.println(doc_id); outFile.delete(); } } catch (Exception e) { logger.logMethodBegin(e.toString()); reqDC.addObject("Exception", e.toString()); throw new ActionException(e); } finally { } return dc; } }