Link to home
Start Free TrialLog in
Avatar of Sh_Rashed
Sh_Rashed

asked on

MultipartParse upload image

Hey,

i got the code from this link

 https://www.experts-exchange.com/questions/20878588/Uploading-images-using-JSP.html?sfQueryTermInfo=1+imag+jsp+upload

and i tried to run it on my machine . i have MultipartParser installed in my project correctly. but when i try to use the above method to use MultipartParser package i got this error:
cannot find symbol
---------------------------------------
 if (fileName != null) {

            filePart.writeTo(dir);
            files.put(name, new UploadedFile(    //files is a variable of the class MultipartRequest
                        dir.toString(), fileName, filePart.getContentType()));
          }
          else {

            files.put(name, new UploadedFile(null, null, null));
          }
-----------------------------------------

i don't know where the hill this constructor UploadedFile defined ? is it in orielly packge?

help please
Avatar of ali_pakkan
ali_pakkan
Flag of Türkiye image

Yes it is in oreilly package..

Its full name is: com.oreilly.servlet.UploadedFile
 
UploadedFile exists in cos.jar, which you can extract from the cos-26Dec2008.zip/lib that you can download from the following site:

http://www.servlets.com/cos/index.html

Hope that solves your problem..
The solution you are looking at date back to 2004

Since then UploadedFile is excluded from the latest package

You might want to download the previous package from here
http://mirrors.ibiblio.org/pub/mirrors/maven/com.servlets/jars/cos-09May2002.jar

Avatar of Sh_Rashed
Sh_Rashed

ASKER

Thanks for ur responses

ali_pakkan:
 the uploadedFile class is not included in this version

bluebelldiscovery:
i have added the package jar file to the lib of the project. now it gives me different error:
uploadedFile is not public cannot be accessed from outside the package?
ASKER CERTIFIED SOLUTION
Avatar of bluebelldiscovery
bluebelldiscovery
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for the code,

i used ur code, when i print request.getContentType it gives null:

<form ENCTYPE="multipart/form-data" ACTION="SaveImage2File" METHOD="GET">
            <br><br><br>
            <center><table border="2" >
                <tr><center><td colspan="2"><p align="center"><B>PROGRAM FOR UPLOADING THE FILE</B><center></td></tr>
                <tr><td><b>Choose the file To Upload:</b>
                    </td>
                <td><INPUT NAME="F1" TYPE="file"></td></tr>
                <tr><td colspan="2">
                <p align="right"><INPUT TYPE="submit" VALUE="Send File" ></p></td></tr>
                <table>
            </center>      
        </form>

this is my html form
1. Input name for "type file" have to be "file"
        <INPUT NAME="file" TYPE="file">
    because servlet is look for this name
        if( name.equals("file") && !item.isFormField())

2. Change form method to POST, so far I have not try GET method not sure if it work.
  <form ENCTYPE="multipart/form-data" ACTION="SaveImage2File" METHOD="POST">

Thanks, it works fine. appreciated :)
I just looked in the jar file, and found the class you're looking for. I didnt think you were just looking for a general upload solution.

Anyhow, i'm happy that it's solved.