tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jose Euclides da Silva Junior - DIGR.O" <jose.eucli...@rj.previdenciasocial.gov.br>
Subject RES: file upload servlet
Date Fri, 29 Dec 2000 13:25:30 GMT
-----BEGIN PGP SIGNED MESSAGE-----

I think that you can not mix parameters and file when you use
MultipartRequest ( from Jason') to handle multipart/form-data.
Regards,

José Euclides Júnior
__________________________________
E-mail: jose.euclides@rj.previdenciasocial.gov.br
            javabrasil@usa.net 
            bl1link@usa.net
http://euclides.8m.com


- -----Mensagem original-----
De:		Tim Cronin [SMTP:tcronin@AUSTIN.CollegeClub.com]
Enviada em:		Quarta-feira, 27 de Dezembro de 2000 22:50
Para:		'tomcat-user@jakarta.apache.org'
Assunto:		RE: file upload servlet

I'm using it on nt4 sun JDK 1.3, tomcat 3.1, apache 1.3.12
and on RH linux 6.2 sun JDK 1.3, tomcat 3.1, apache 1.3.12

I'm waiting till all the bleeding edgers debug 3.2....

Initially I had some funky behavior when I ccped from the upload
examples, but I rewrote it from scratch and it seems to work ok.


- -----Original Message-----
From: mayan@nytimes.com [mailto:mayan@nytimes.com]
Sent: Wednesday, December 27, 2000 6:40 PM
To: tomcat-user@jakarta.apache.org
Subject: RE: file upload servlet




I am very surprised. I tried the same version.

Here is the code I am using. As you can see, (or somebody can see), this is
from
upload.war (the sample came with the multirequest class) with some
modifications.

If everything works ok, I should be able to see all the parameters and files
listed. However, it only worked for text files. For binary files, results
vary
from server error to exception in the MultiPartRequest constrcutor. The only
difference I could find between your code and mine is mine is in a servlet's
doPost() function?

Now I am really confused. Help!

Is it related to tomcat somehow. I am using tomcat 3.2.1 with apache 1.3.14
on
WinNT4.0.

Yanbin




          try {
            MultipartRequest multi =
              new MultipartRequest(req, "D:/upload");

            writer.println("<P>Params:</P>");
            Enumeration params = multi.getParameterNames();
            while (params.hasMoreElements()) {
              String name = (String)params.nextElement();
              String value = multi.getParameter(name);
              writer.println("<p>" + name + " = " + value + "</P>");
            }
            writer.println();

            writer.println("<p>Files:</p>");
            Enumeration files = multi.getFileNames();
            while (files.hasMoreElements()) {
              String name = (String)files.nextElement();
              String filename = multi.getFilesystemName(name);
              String type = multi.getContentType(name);
              File f = multi.getFile(name);
              writer.println("<p>" + "name: " + name + "</p>");
              writer.println("<p>" + "filename: " + filename + "</p>");
              writer.println("<p>" + "type: " + type + "</p>");
              if (f != null) {
                writer.println("<p>" + "f.toString(): " + f.toString() +
"</p>");
                writer.println("<p>" + "f.getName(): " + f.getName() +
"</p>");
                writer.println("<p>" + "f.exists(): " + f.exists() +
"</p>");
                writer.println("<p>" + "f.length(): " + f.length() +
"</p>");
                writer.println("<p></p>");
              }
            }
          }
          catch (IOException lEx) {
            this.getServletContext().log("error reading or saving file" +
lEx,
lEx);
          }
          catch (Exception e)
          {
               this.getServletContext().log("caught un-known exception" + e,
e);
          }



|--------+-------------------------------->
|        |          Tim Cronin            |
|        |          <tcronin@AUSTIN.Colleg|
|        |          eClub.com>            |
|        |                                |
|        |          12/27/00 06:47 PM     |
|        |          Please respond to     |
|        |          tomcat-user           |
|        |                                |
|--------+-------------------------------->
 
>---------------------------------------------------------------------------
|
  |
|
  |       To:     "'tomcat-user@jakarta.apache.org'"
|
  |       <tomcat-user@jakarta.apache.org>
|
  |       cc:     (bcc: Yanbin Ma/SYS/NYTIMES)
|
  |       Subject:     RE: file upload servlet
|
 
>---------------------------------------------------------------------------
|




I was able to upload text, image, exe files, and other binaries with oreily
package.
I am using the nov 20 2000 version

here's the code from my jsp file

private String processRequest
(
  HttpServletRequest request
)
{
  String cType = request.getContentType();

  if (cType != null &&
cType.toLowerCase().startsWith("multipart/form-data"))
  {
    try
    {
      String appPath = getPath(request);
      MultipartRequest multi = new MultipartRequest(request, appPath);
      String submit = multi.getParameter(SUBMIT_UPLOAD_NAME);
      if(submit != null && (submit.equals(SUBMIT_UPLOAD_VAL)))
      {
        Enumeration files = multi.getFileNames();
        if(!files.hasMoreElements())
        {
          return("No file was uploaded!");
        }
        else
        {
          return("uploaded " +
multi.getFilesystemName((String)files.nextElement()) + " to " + appPath);
        }
      }
    }
    catch(IOException e)
    {
      return(e.getMessage());
    }
  }
  return("");
}

- -----Original Message-----
From: mayan@nytimes.com [mailto:mayan@nytimes.com]
Sent: Wednesday, December 27, 2000 5:37 PM
To: tomcat-user@jakarta.apache.org
Subject: RE: file upload servlet




Thank you, Tim.

I tried this one first before I posted the message. It worked only for text
files.

I tried two versions. The very first and the very last one.

Did you work with this library before? How did you upload binary files?

Yanbin



|--------+-------------------------------->
|        |          Tim Cronin            |
|        |          <tcronin@AUSTIN.Colleg|
|        |          eClub.com>            |
|        |                                |
|        |          12/27/00 06:22 PM     |
|        |          Please respond to     |
|        |          tomcat-user           |
|        |                                |
|--------+-------------------------------->

>---------------------------------------------------------------------------
|
  |
|
  |       To:     "'tomcat-user@jakarta.apache.org'"
|
  |       <tomcat-user@jakarta.apache.org>
|
  |       cc:     (bcc: Yanbin Ma/SYS/NYTIMES)
|
  |       Subject:     RE: file upload servlet
|

>---------------------------------------------------------------------------
|




they have a good multipart form handler.

http://www.servlets.com/resources/com.oreilly.servlet/

the only draw back is you need to know the path
to store the files at before you parse the multipart request.



- -----Original Message-----
From: mayan@nytimes.com [mailto:mayan@nytimes.com]
Sent: Wednesday, December 27, 2000 5:15 PM
To: tomcat-user@jakarta.apache.org
Subject: file upload servlet




Hi all,

Does anybody know a servlet utility that can handle binary file upload?

I appreciate any information you can share.

Ma, Yanbin






-----BEGIN PGP SIGNATURE-----
Version: PGP 6.5.1

iQCVAwUBOkyqgt0YhuJ3BUxtAQG/sgQAvpY6UVvhp6QA9i4ALohm28tgnQdmwiGc
shH5pm0W/jilsLDv5hgTvL4wpvcFZrYDin/r2CLLjZ1XeTvb94UpI4Ib7pxDh9fC
0y2zncAezKAvrrhiWz7o+SJdENTD2gYVaujptZsqIUEu4wh42yBFGgk6WVORviPM
x2WWTByBw74=
=3/00
-----END PGP SIGNATURE-----

Mime
View raw message