commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eric Chow <eric...@gmail.com>
Subject Re: FileUpload problem !!
Date Mon, 17 Jan 2005 08:55:04 GMT
My Code is as following:



<html>
<head>
<title>File Upload</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body bgcolor="#FFFFFF" text="#000000"><p><font size="5"color="#FF0000">
<b>Upload</b></font></p>
 
<form name="Form1" enctype="multipart/form-data" method="post"
action="upload.jsp">
<p>File 1<input type="file"name="File1" size="20" maxlength="20"> </p>
<p>Description 1<input type="text" name="File1" size="30" maxlength="50"> </p>
<p>File 2<input type="file" name="File2" size="20" maxlength="20"> </p>
<p>Description 2<input type="text" name="File2" size="30" maxlength="50"> </p>
<p>File 3<input type="file" name="File3" size="20" maxlength="20"> </p>
<p>Description 3<input type="text" name="File3" size="30" maxlength="50"> </p>
<p> <input type="submit"value="Upload"> <input type="reset" value="Clear">
</p>
</form>
 
</body>
</html>




<?%@ page contentType="text/html;charset=UTF-8" language="java"
pageEncoding="UTF-8"%>
<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %>
<%@ page import="org.apache.commons.fileupload.*" %>
 
<% 
 	request.setCharacterEncoding("UTF-8");
 
    String saveDirectory = "c:\\";
    String tmpDirectory = "c:\\";
    int maxPostSize = 1024 * 1024; 
%>
<%
    String FileDescription = null; 
    String FileName = null;
    long FileSize = 0;
    String ContentType = null;
    int count = 0 ;
%>
 
<% 
    DiskFileUpload upload = new DiskFileUpload();
    
    upload.setSizeThreshold(4096);
       
    upload.setSizeMax(maxPostSize);
      
    upload.setRepositoryPath(tmpDirectory);
    List items = upload.parseRequest(request);
%>
<body>
<% 
 Iterator iter = items.iterator();
 
    int tmp = 0;
    FileItem tmpItem = null;
 while (iter.hasNext()) 
 { 
        tmp++;
        FileItem item = (FileItem) iter.next();
        
        if (item.isFormField()) {        
            FileDescription = item.getString();            
        } else {        
            FileName = item.getName();
  
  try {
   // for wintel platform
    FileName = FileName.substring(FileName.lastIndexOf("\\")+1);
  // for unix-like platform
    FileName = FileName.substring(FileName.lastIndexOf("/")+1); 
  } catch ( Exception ex ) {
 out.println(ex);
  }
 

            ContentType = item.getContentType();
            FileSize = item.getSize();
            tmpItem = item;        
        }
        
  if (tmp == 2 && FileSize != 0)
  { 
   count ++;
 
%>
<font color="red">Total file uploaded: <%= count %></font><br>
File name: <%= FileName %><br>
File size: <%= FileSize %> Bytes<br>
Content type: <%= ContentType %><br>
Description: <%= FileDescription %><br><br>
 
<%        
   try {
      out.println(FileName);
      File uploadedFile = new File(saveDirectory + FileName);
      tmpItem.write(uploadedFile);
   } catch ( Exception ex ) {
      out.println(ex);
    }
            
            tmp = 0;
        } else if (tmp == 2 && FileSize == 0) {
            tmp = 0;
  } // end if 
 } // end while
%> 
<font color="red"><%= count %></font>
</body>
</html>






On Sun, 16 Jan 2005 21:08:16 -0800, Dakota Jack <dakota.jack@gmail.com> wrote:
> Can you give your code?  I am having trouble determining what you are
> having difficulty with here.  Give the code or a better description of
> what you find you cannot do.
> 
> Jack
> 
> 
> On Mon, 17 Jan 2005 12:12:36 +0800, Eric Chow <eric138@gmail.com> wrote:
> > Hello,
> >
> > I used Struts' file upload example to upload file (multipart), it
> > works file with (UTF-8 description).
> >
> > I am now going to use  commons-fileupload. But it failed to include a
> > UTF-8 description, after I uploaded the file and want to display the
> > description, it just display some unreadable character, cannot display
> > my input characters.
> >
> > Any sugegst and idea on it ?
> >
> > Eric
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: commons-user-help@jakarta.apache.org
> >
> >
> 
> --
> ------------------------------
> 
> "You can lead a horse to water but you cannot make it float on its back."
> 
> ~Dakota Jack~
> 
> "You can't wake a person who is pretending to be asleep."
> 
> ~Native Proverb~
> 
> "Each man is good in His sight. It is not necessary for eagles to be crows."
> 
> ~Hunkesni (Sitting Bull), Hunkpapa Sioux~
> 
> -----------------------------------------------
> 
> "This message may contain confidential and/or privileged information.
> If you are not the addressee or authorized to receive this for the
> addressee, you must not use, copy, disclose, or take any action based
> on this message or any information herein. If you have received this
> message in error, please advise the sender immediately by reply e-mail
> and delete this message. Thank you for your cooperation."
>

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