"request was rejected because no multipart boundary was found" while using httprequest

4,577 views
Skip to first unread message

rakesh

unread,
Oct 29, 2008, 4:32:08 PM10/29/08
to Gears Users
I hav a simple code that attempts to use Desktop for multiple file
upload to a server(a simple file upload servlet hosted on jboss and
written using apache-file-upload).

Once I open the request,
this is how I set it to be multiplart content:
request.setRequestHeader("Content-type", "multipart/mixed");

On the server I get the following exception:

org.apache.commons.fileupload.FileUploadException: the request was
rejected because no multipart boundary was found


Am I missing something in the header? all help appreciated!!!

Michael Nordman

unread,
Oct 30, 2008, 3:11:41 PM10/30/08
to gears...@googlegroups.com
Looks like you are trying to emulate a typical form post. The content type typically used is multipart/form-data. The full content type header also needs to indicate the boundary used within the post data to delineate the different parts... here's some pseudo code.

        string    sCRLF = "\r\n";
        string    sDashes = "--";
        string    sBoundary = "some dashes and numbers and letters that does not occur in element names|values|filedata"; 
        string    sMultipartContentType = "multipart/form-data; boundary=" + sBoundary; 

                 foreach (formfield) {
                    WriteString( stream, sDashes + sBoundary + sCRLF ); 
                    WriteString( stream, "Content-Disposition: form-data; name= formfield.name " + sCRLF );
                    WriteString( stream, sCRLF ); 
                    WriteString( stream, field.value);
                    WriteString( stream, sCRLF );
                }

                foreach (formfile) {
                    WriteString( stream, sDashes + sBoundary + sCRLF ); 
                    WriteString( stream, "Content-disposition: form-data; name= formfile.name; filename=formfile.filename" + sCRLF );
                    WriteString( stream, sCRLF ); 
                    WriteStream( stream, formfile.filestream);
                    WriteString( stream, sCRLF ); 
                }

                 if ((formfields.Count > 0) || (formfiles.Count > 0))  {
                    WriteString( stream, sDashes + sBoundary + sDashes + sCRLF ); 
                } 
Reply all
Reply to author
Forward
0 new messages