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 |
| | <[EMAIL PROTECTED]|
| | eClub.com> |
| | |
| | 12/27/00 06:47 PM |
| | Please respond to |
| | tomcat-user |
| | |
|--------+-------------------------------->
>---------------------------------------------------------------------------|
| |
| To: "'[EMAIL PROTECTED]'" |
| <[EMAIL PROTECTED]> |
| 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: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, December 27, 2000 5:37 PM
To: [EMAIL PROTECTED]
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 |
| | <[EMAIL PROTECTED]|
| | eClub.com> |
| | |
| | 12/27/00 06:22 PM |
| | Please respond to |
| | tomcat-user |
| | |
|--------+-------------------------------->
>---------------------------------------------------------------------------
|
|
|
| To: "'[EMAIL PROTECTED]'"
|
| <[EMAIL PROTECTED]>
|
| 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: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, December 27, 2000 5:15 PM
To: [EMAIL PROTECTED]
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