Wrox Home  
Search P2P Archive for: Go

  Return to Index  

servlets thread: Re: Uploading a file to the server(oreilly's MultiPartRequest class)


Message #1 by "Pierre Carlo Cornago" <piyerr@y...> on Mon, 1 Jul 2002 06:11:56
Hello,

I am also creating an Upload Servlet...
I have also encountered similar errors like your.
If you have you already solve your problem, could i ask for your help?
Thank you.

Piyer

> Hi,
> I have been trying to write a servlet which will upload a file to the 
> server.For that i used oreilly's MultiPartRequest class. Iam sending 
data 
> through http header from swing interface like that:-
> 
> Button.addActionListener(new ActionListener()
> 			 {
>                            public void actionPerformed(ActionEvent e)
> 				 {
> int returnVal = fc.showOpenDialog(ActionDemo4.this);
> 
>                 		      if (returnVal == 
> JFileChooser.APPROVE_OPTION) {
>                     		      File file = fc.getSelectedFile
();
>                                       String aa=file.getAbsolutePath();
> 		                      textArea3.append(aa);
> 			              textArea2.append("Local URL:");
>                                       long l=file.length();
> 		try
> 		   {
> 		   byte buff[]=new byte[(int)file.length()];
> 		   InputStream fileIn=new FileInputStream(aa);
> 		   int i=fileIn.read(buff);
> 		   String conffile=new String(buff); 
> url = new URL ("http://127.0.0.1:7001/FileUpload?x="+str1);
> 
> 
> urlConn = url.openConnection();
> 
> urlConn.setDoInput (true);
> 
> urlConn.setDoOutput (true);
> 
> 
> urlConn.setUseCaches (false);
> 
> 
> urlConn.setRequestProperty("Content-Type","multipart/form-data;boundary=-
--
> --------------------------7d01ecf406a6");
> 
> 
> printout = new DataOutputStream (urlConn.getOutputStream ());
> 
> String content="-----------------------------7d01ecf406a6\r\n"+"Content-
> Disposition: form-data;"+"name=\"upload\"; 
> filename=\""+aa+"\"\r\n"+"Content-Type: 
text/plain\r\n\r\n\r\n"+conffile+"-
> ----------------------------7d01ecf406a6--\r\n";
> printout.writeBytes(content);
> printout.flush ();
> printout.close (); 
> But i get the following exception:
> ----------------------------------
> java.io.IOException: Corrupt form data: no leading boundary
> at com.oreilly.servlet.MultipartRequest.readRequest
> (MultipartRequest.java:361)
> at com.oreilly.servlet.MultipartRequest.<init>(MultipartRequest.java:149)
> at FileUpload.doPost(FileUpload.java:23)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
> at weblogic.servlet.internal.ServletStubImpl.invokeServlet
> (ServletStubImpl.java:213)
> at weblogic.servlet.internal.WebAppServletContext.invokeServlet
> (WebAppServletContext.java:1265)
> at weblogic.servlet.internal.ServletRequestImpl.execute
> (ServletRequestImpl.java:1622)
> at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:137)
> at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
> 
> 
> Plz guide me where i done a mistake.
> 
> Regards
> Bikash
> 

  Return to Index