Hi,
can you try the same code (doFileUpload() and upload.php )both client and server with your url and let me know whether that code worked for you? Please use upload.php code and create a folder named uploads in your localhost directory.



venkat wrote:Dear Katharnavas,:)
Is it possible to upload files using httpclient ??.
Thanks and Regards,
Venkat.

rmeph wrote:thanks a lotssssssssssssss........it's working![]()
i try "PUT" method in client side to upload file server.....but without using server side coding
use code
Using java Syntax Highlighting
HttpURLConnection conn = null; DataOutputStream dos = null; DataInputStream inStream = null; String exsistingFileName = aDirectory.getAbsolutePath(); // Is this the place are you doing something wrong. String lineEnd = "\r\n"; String twoHyphens = "--"; String boundary = "*****"; int bytesRead, bytesAvailable, bufferSize; byte[] buffer; int maxBufferSize = 1*1024*1024; String responseFromServer = ""; String urlString = "http://www.isol.co.in/isol_final/"; try { //------------------ CLIENT REQUEST Log.e("fileupload","Inside second Method"); FileInputStream fileInputStream = new FileInputStream(new File(exsistingFileName) ); // open a URL connection to the Servlet URL url = new URL(urlString); // Open a HTTP connection to the URL conn = (HttpURLConnection) url.openConnection(); // Allow Inputs conn.setDoInput(true); // Allow Outputs conn.setDoOutput(true); // Don't use a cached copy. conn.setUseCaches(false); // Use a post method. conn.setRequestMethod("PUT"); conn.setRequestProperty("Connection", "Keep-Alive"); conn.setRequestProperty("Content-Type", "multipart/form-data;boundary="+boundary); dos = new DataOutputStream( conn.getOutputStream() ); dos.writeBytes(twoHyphens + boundary + lineEnd); dos.writeBytes("Content-Disposition: form-data; name="uploadedfile";filename="" + exsistingFileName +""" + lineEnd); dos.writeBytes(lineEnd); Log.e("MediaPlayer","Headers are written"); // create a buffer of maximum size bytesAvailable = fileInputStream.available(); bufferSize = Math.min(bytesAvailable, maxBufferSize); buffer = new byte[bufferSize]; // read file and write it into form... bytesRead = fileInputStream.read(buffer, 0, bufferSize); while (bytesRead > 0) { dos.write(buffer, 0, bufferSize); bytesAvailable = fileInputStream.available(); bufferSize = Math.min(bytesAvailable, maxBufferSize); bytesRead = fileInputStream.read(buffer, 0, bufferSize); } // send multipart form data necesssary after file data... dos.writeBytes(lineEnd); dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd); // close streams Log.e("fileupload","File is written"); fileInputStream.close(); dos.flush(); dos.close(); } catch (MalformedURLException ex) { Log.e("fileupload", "error: " + ex.getMessage(), ex); } catch (IOException ioe) { Log.e("MediaPlayer", "error: " + ioe.getMessage(), ioe); } //------------------ read the SERVER RESPONSE try { BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream())); String line; while ((line = rd.readLine()) != null) { showAlert("Dialoge Box", "Message: " + line,"OK", false); } rd.close(); } catch (IOException ioex){ Log.e("MediaPlayer", "error: " + ioex.getMessage(), ioex); }Parsed in 0.050 seconds, using GeSHi 1.0.8.4
it's shoe exception is
E/fileupload<764>:error: http"//www.isol.co.in/isol_final/<HTTP 405- Method Not Allowed>
E/fileupload<764>:java.io.FileNotExceptionException:http"//www.isol.co.in/isol_final/<HTTP 405- Method Not Allowed>
E/fileupload<764>: at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:885)
E/fileupload<764>: at org.anddev.android.filebowser.AndroidfileBowser$1.onClick<AndroidfileBowser.java:192>
E/fileupload<764>: at android.app.AlertDialog$2.handleMessage<AlertDialog.java:437>
E/fileupload<764>: st android.os.Handler.dispatchMessage<Hanlder.java:80>
E/fileupload(764): at android.os.Looper.loop(Looper.java:71)
E/MediaPlayer(764): at android.app.ActivityThread.main(ActivityThread.java:2506)
E/fileupload(764): at java.lang.reflect.Method.invokeNative(Native Method)
E/fileupload(764): at java.lang.reflect.Method.invoke(Method.java:380)
E/MediaPlayer(764): at android.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1170)
E/fileupload(764): at android.os.ZygoteInit.main(ZygoteInit.java:1121)
E/fileupload(764): at android.dalvik.NativeStart.main(Native Method)
plz tel me why it's show that exception??




Users browsing this forum: Google [Bot] and 5 guests