This code uploads a file to the Content manager(FileNet).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | 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; } } |