You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Ang Ho Keat <g0...@nus.edu.sg> on 2004/06/28 11:08:28 UTC

[FileUpload] Corrupted uploaded binary (MS Excel) file

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);

RE: [FileUpload] Corrupted uploaded binary (MS Excel) file

Posted by Schalk <sc...@volume4.co.za>.
Have you tried reading this in via an input stream and writing out via an
output stream.

Kind Regards
Schalk Neethling
Web Developer.Designer.Programmer.President
Volume4.Development.Multimedia.Branding
emotionalize.conceptualize.visualize.realize
Tel: +27125468436
Fax: +27125468436
email:schalk@volume4.co.za
web: www.volume4.co.za
 
This message contains information that is considered to be sensitive or
confidential and may not be forwarded or disclosed to any other party
without the permission of the sender. If you received this message in error,
please notify me immediately so that I can correct and delete the original
email. Thank you. 

:: -----Original Message-----
:: From: Ang Ho Keat [mailto:g0308041@nus.edu.sg]
:: Sent: Monday, June 28, 2004 11:08 AM
:: To: commons-user@jakarta.apache.org
:: Subject: [Norton AntiSpam] [FileUpload] Corrupted uploaded binary (MS
Excel) file
:: 
:: 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);



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org