commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Edward S" <sumi...@gmail.com>
Subject Re: File Upload Exception - request doesn't contain a multipart/form-data or multipart/mixed stream, content type header is application/x-www-form-urlencoded
Date Tue, 26 Feb 2008 15:40:36 GMT
great thanks...tht worked



On 2/25/08, Bronwyn Cook <bronwyn@geometryit.com> wrote:
>
> Edward S <suminub <at> gmail.com> writes:
>
> >
> > Martin
> >
> > I tried both.
> > the thing is, apart from the file parameter in the form there is another
> > hidden field that contains a text value.
> > if i use multipart/form-data, tht hidden field comes up as null.
> >
> > -S2.
> >
> > On 2/7/08, Martin Cooper <martinc <at> apache.org> wrote:
> > >
> > > On Feb 7, 2008 8:15 PM, Edward S <suminub <at> gmail.com> wrote:
> > >
> > > > Hey guys,
> > > >
> > > > I am tryin to upload a JPG file and am getting this error:
> > > >
> > > >
> > > >
> > >
>
> org.apache.commons.fileupload.FileUploadBase$InvalidContentTypeException:the
> > > > request doesn't contain a multipart/form-data or multipart/mixed
> > > > stream,
> > > > content type header is application/x-www-form-urlencoded
> > > >
> > > >
> > > > let me explain what I am doing:
> > > >
> > > > I have a JSP that has the form that does the file upload. the
> enctype on
> > > > the
> > > > form is "multipart/mixed"
> > >
> > >
> > > That's the problem, assuming you are submitting from a browser. AFAIK,
> > > 'multipart/mixed' is neither valid nor supported in HTML, so the
> browser
> > > is
> > > ignoring your value and falling back to the HTML default, which is
> > > 'application/x-www-form-urlencoded'. To post the file, you'll need to
> use
> > > 'multipart/form-data'.
> > >
> > > --
> > > Martin Cooper
> > >
> > >
> > >
> > > > this JSP is included in a root JSP and the action submits the form
> to
> > > the
> > > > root JSP.
> > > >
> > > > Root JSP has a controller, that processes the request. When it tries
> to
> > > > process this request, it gives me the above mentioned error.
> > > >
> > > > Any idea, where I am going wrong?
> > > >
> > > > thanks
> > > >
> > > > Ed.
> > > >
> > >
> >
>
>
>
> I had this problem and it was because I was using the 'normal' way of
> getting
> the input parameters from the request object (eg. request.getParameter
> ("name")) instead of traversing the items from the multipart request.
>
> If ServletFileUpload.isMultipartContent(request) returns true then you
> need to
> get the fields via the upload.parseRequest(request) method.
>
> eg:
>
> // Check that we have a file upload request
> boolean isMultipart = ServletFileUpload.isMultipartContent(request);
> if(isMultipart)
> {
>        // Create a factory for disk-based file items
>        DiskFileItemFactory factory = new DiskFileItemFactory();
>
>        // Set factory constraints
>        factory.setSizeThreshold(1000000);
>        factory.setRepository( ConfigServlet.getTempDirectory() );
>
>        // Create a new file upload handler
>        ServletFileUpload upload = new ServletFileUpload(factory);
>
>        // Set overall request size constraint
>        upload.setSizeMax(10000000);
>
>        // Parse the request
>        List<FileItem> items;
>        try {
>                items = upload.parseRequest(request);
>
>                for(FileItem item : items)
>                {
>
>                        if (item.isFormField()) {
>                                String name = item.getFieldName();
>                                String value = item.getString();
>                                query.put(name, value);
>
>                        }
>                        else // file object
>                        {
>                            // do stuff for file request
>
>                        }
>
>                }
>        } catch (FileUploadException e) {
>                        // TODO Auto-generated catch block
>                        e.printStackTrace();
>        }
> }
> else
> {
>        query = new TreeMap<String, Object>();
>        Map tbl = request.getParameterMap();
>        query.putAll( tbl );
> }
>
>
> Hope this helps you
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message