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 RE: [FileUpload] Corrupted uploaded binary (MS Excel) file
Date Tue, 29 Jun 2004 03:38:57 GMT
Hi,
 
I modified part of my code.
 
I tried sending 2 binary files instead of one.  The first binary file will always be corrupted;
the second one will be fine.  Why?  Bug?
 
:: ************************************
:: Client-Side HTML
:: ************************************
<form name="myForm" action="import.jsp" method="POST" enctype="multipart/form-data">
  <input type='hidden' name='dummy' value='dummy'>
  <table border="1">
    <tr>
      <td class='header'>Select Excel File for uploading </td>
      <td><input type="file" name="srcfile" size="30"></td>      
    </tr>
    <tr>
      <td class='header'>Select Excel File for uploading </td>
      <td><input type="file" name="srcfile2" size="30"></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
:: ************************************
   Iterator iter = list.iterator();
   while (iter.hasNext()) {
      FileItem fileItem = (FileItem)iter.next();
      if (!fileItem.isFormField()) {
         String EXCEL_FILENAME = "tmp" + random.nextInt() +".xls";   
         File resultFile = new File(dir, EXCEL_FILENAME);
         fileItem.write(resultFile);
      } else {
         System.out.println(fileItem.getFieldName() +"-"+fileItem.getString());
      }
   }

	-----Original Message----- 
	From: Ang Ho Keat 
	Sent: Tue 6/29/2004 10:52 AM 
	To: Jakarta Commons Users List 
	Cc: 
	Subject: RE: [FileUpload] Corrupted uploaded binary (MS Excel) file
	
	

	I tried using the inputStream from the fileItem and writing the contents to a File, but the
result is the same - file is still corrupted.
	
	I dont know how to use the inputStream from the request directly as there are HTML headers
in the stream.
	
	        -----Original Message-----
	        From: Schalk [mailto:schalk@volume4.co.za]
	        Sent: Mon 6/28/2004 8:20 PM
	        To: 'Jakarta Commons Users List'
	        Cc:
	        Subject: RE: [FileUpload] Corrupted uploaded binary (MS Excel) file
	       
	       
	
	        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
	       
	       
	
	

Mime
View raw message