> I am using MultipartParser to upload files.
> The codes compiles successfully.
> But when I run it, I find that the uploaded file is empty.
> Please see my code below and comment.

The problem is that the parts of the MultiParser is an interface to 1 single Part 
object (I
guess to save memory). So everytime you do mp.readNextPart() it will override this one
object. So what you should do is to deal with the file right away. See the inline 
correction
in your code.
I think that should make it work...

Frans

>                 MultipartParser mp = new MultipartParser(env.req, 10*1024*1024);
>                 Part part;
>                 String path = null;
>                 FilePart filePart = null;
>                 String fileName = null;
>
File uploadDir = new File("/home/www/dramamurthy/sitebuilder/WEB-INF/Uploads/");
if (!uploadDir.exists()) {
    uploadDir.mkdir();
}
>                 while ((part = mp.readNextPart()) != null) {
>                         String name = part.getName();
>                         if (part.isParam()) {
>                                 ParamPart paramPart = (ParamPart) part;
>                                 if (name.equals("path")){
>                                         path = paramPart.getStringValue();
>                                 }
>                         } else if (part.isFile()) {
>                                 filePart = (FilePart) part;
>                                 fileName = filePart.getFileName();
                                   // write the file right away, before part gets a 
new value through
the method mp.readNextPart()
                                   if (fileName != null) {
                                       long size = filePart.writeTo(uploadDir);
                                   }
>                         }
>                 }
// Moved upwards
// File uploadDir = new File("/home/www/dramamurthy/sitebuilder/WEB-INF/Uploads/");
//                 if (!uploadDir.exists()) {
//                         uploadDir.mkdir();
//                 }
// Moved to inside the while loop
//                 if (fileName != null) {
//                         long size = filePart.writeTo(uploadDir);
//                 }
>
> ___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to