commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ang Ho Keat" <g0308...@nus.edu.sg>
Subject [FileUpload] Corrupted uploaded binary (MS Excel) file
Date Mon, 28 Jun 2004 09:08:28 GMT
Hi,
 
I am able to get a text file to upload successfully but not a binary (Excel) file.  Though
the uploading did not report any error, I get an error message when I tried to open the uploaded
excel file stating that the file is corrupted.
 
Any help will be much appreciated.  Code snippets are appended below.  Running on Resin 3.0.8
and win2000 and JDK 1.4.2.
 
************************************
Client-Side HTML
************************************
<form name='myForm' id='myForm' method="POST" action="import.jsp" enctype="multipart/form-data">
  <table border="1">
    <tr>
      <td class='header'>Select Excel File for uploading </td>
      <td><input type="file" name="srcfile" size="20"></td>
    </tr>
  </table>
  <p><input type="button" value="Submit" name="B1" onclick='formSubmit()'> <input
type="reset" value="Reset" name="B2"></p>
</form>
 
************************************
Server-Side JSP
************************************
File resultFile = new File(dir, EXCEL_FILENAME);
   boolean isMultipart = FileUpload.isMultipartContent(request);
   if (!isMultipart) {
      throw new Exception("Request is not 'multipart/form-data'.");
   }
   DiskFileUpload upload = new DiskFileUpload();
   upload.setRepositoryPath(dir);
   List list = upload.parseRequest(request);
   if (list.size()!=1) {
      throw new Exception("Please upload only 1 file.");
   } else if (list.size()==0) {
      throw new Exception("No file uploaded.");
   }
   FileItem fileItem = (FileItem)list.get(0);
   fileItem.write(resultFile);
Mime
View raw message