raju
raju

Reputation: 785

java.io.IOException: Posted content type isn't multipart/form-data

I have written a jsp page for uploading image using POST method by using com.oreilly.servlet.multipart.MultipartParser actually file is successfully uploading and post values also getting correctly but it is throwing a exception

java.io.IOException: Posted content type isn't multipart/form-data 
MultipartParser mp = null;
try{
 mp = new MultipartParser(request, 1*1024*1024); // 10MB
 }
 catch(Exception e){
 out.println("Exception1:"+e);
 }
while ((part = mp.readNextPart()) != null) {
        name = part.getName();
        if (part.isParam()) {
            ParamPart paramPart = (ParamPart) part;
            value = paramPart.getStringValue();
            if(name.equals("companyname") && value != null){                

            }

            if(name.equals("version") && value != null && name != null){

            }

        }
        else if (part.isFile()) {
            String getimagelogovalue="";
            FilePart filePart = (FilePart) part;
            String fileName = filePart.getFileName();
            if (fileName != null) {

            }
            else {}
            out.flush();
        }
    }   

Upvotes: 2

Views: 11160

Answers (3)

Pavan Kumar.R
Pavan Kumar.R

Reputation: 11

I Just changed

enctype="multipart/form-data"

to ENCTYPE="multipart/form-data"

in form tag

The Exception is resolved , and the form tag is below

 <form method="POST"  name="form1"  action="1StudentDVerify.jsp" ENCTYPE="multipart/form-data">


</form>

Upvotes: 1

Sap
Sap

Reputation: 5321

I think the code that you have written over here is the server side code, assuming that you are doing a post form JSP your code should look like following

<FORM action="http://server.com/cgi/handle"
       enctype="multipart/form-data"
       method="post">
   <P>
   What is your name? <INPUT type="text" name="submit-name"><BR>
   What files are you sending? <INPUT type="file" name="files"><BR>
   <INPUT type="submit" value="Send"> <INPUT type="reset">
 </FORM>

See the enctype attribute. Also can we see the client side(JSP) code?

The code snippet is taken from http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.2

Upvotes: 2

Dave Richardson
Dave Richardson

Reputation: 5005

You have:

mp = new MultipartParser(request, 1*1024*1024); // 10MB

but by my calculations that is actually only 1Mb. Is the image you are trying to upload actually too large? Try smaller images, fix your comment or fix your code.

Upvotes: 2

Related Questions