Using the Jakarta Commons, Part 1
Subject:   FileUpload
Date:   2003-06-26 08:54:36
From:   anonymous2
FileUpload package has just gone 1.0 final these days.
Full Threads Newest First

Showing messages 1 through 1 of 1.

  • FileUpload is not identifying html file element.
    2006-11-20 08:59:59  Rocke [View]

    I hava a problem in using commons upload component.
    I have the foll. code in my jsp.
    <form name="myform" action="/surety/"
    method="post" enctype="multipart/form-data">
    <input type="file" name="myfile">

    <input type="submit" name="Submit" value="Submit your files"/>
    In my action class,
    List fileItems = upload.parseRequest(request) is returning 0. It is not identifying the html file element.
    Now if I add one more html file element, then the list returned will be 1,which is the second one I added.
    What could be the reason. I use struts and I followed all the changes required for this.
    My action class code is:

    DiskFileItemFactory factory=new DiskFileItemFactory();
    ServletFileUpload upload=new ServletFileUpload(factory);

    // If file size exceeds, a FileUploadException will be thrown

    List fileItems = upload.parseRequest(request);
    System.out.println("Size of the list is "+fileItems.size());
    Iterator iter = fileItems.iterator();
    while (iter.hasNext()) {
    FileItem fi = (FileItem);
    String fileName = fi.getName();
    // save comment and filename to database
    // write the file
    //fi.write(new File("C:/Rocke"));
    byte[] result = null;
    byte[] buffer = new byte[8196];
    int len = 0;
    InputStream istream = fi.getInputStream();
    ByteArrayOutputStream ostream = new ByteArrayOutputStream();
    while ((len = != -1) {
    result = ostream.toByteArray();
    FileOutputStream outFile = new FileOutputStream("C:/Test.pdf");