uploading files in android using emulator and localsystem
<p>hi friends iam trying to upload a file from the android device to the server.i tried it with emulator and localhost  but it does not working.
i am using wamp server in local system . my android code for upload file is given below. i need  uploading file from emulator to localsystem</p>

<p>upload.java</p>

<pre><code>HttpURLConnection conn = null;
DataOutputStream dos = null;
DataInputStream inStream = null;
String existingFileName =FileName.getText().toString();
String lineEnd = "\r\n";
String twoHyphens = "--";
String boundary =  "*****";
int bytesRead, bytesAvailable, bufferSize;
byte[] buffer;
int maxBufferSize = 1*1024*1024;
//String responseFromServer = "";
String urlString="http://localhost/uploads/upload.php";

try
{

FileInputStream fileInputStream = new FileInputStream(new File(existingFileName) );
 // open a URL connection to the Servlet
 URL url = new URL(urlString);

 conn = (HttpURLConnection) url.openConnection();

 conn.setDoInput(true);

 conn.setDoOutput(true);

 conn.setUseCaches(false);

 conn.setRequestMethod("POST");
 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=\"" + existingFileName + "\"" + lineEnd);
 dos.writeBytes(lineEnd);

 bytesAvailable = fileInputStream.available();
 bufferSize = Math.min(bytesAvailable, maxBufferSize);
 buffer = new byte[bufferSize];

 bytesRead = fileInputStream.read(buffer, 0, bufferSize);
 while (bytesRead &gt; 0)
 {
  dos.write(buffer, 0, bufferSize);
  bytesAvailable = fileInputStream.available();
  bufferSize = Math.min(bytesAvailable, maxBufferSize);
  bytesRead = fileInputStream.read(buffer, 0, bufferSize);
 }

 dos.writeBytes(lineEnd);
 dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);

 Log.e("Debug","File is written");
 fileInputStream.close();
 dos.flush();
 dos.close();
 Toast.makeText(Upload.this, "Files have been uploaded successfully",Toast.LENGTH_SHORT).show();
}
catch (MalformedURLException ex)
{
     Log.e("Debug", "error: " + ex.getMessage(), ex);
}
catch (IOException ioe)
{
     Log.e("Debug", "error: " + ioe.getMessage(), ioe);
}

try {
      inStream = new DataInputStream ( conn.getInputStream() );
      String str;

      while (( str = inStream.readLine()) != null)
      {
           Log.e("Debug","Server Response "+str);
      }
      inStream.close();

}
catch (IOException ioex)
{
     Log.e("Debug", "error: " + ioex.getMessage(), ioex);
}
</code></pre>

<p>here is my php code</p>

<p>upload.php</p>

<pre><code>&lt;?php

 $target_path = "uploads/";

 $target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

 if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']).
    " has been uploaded";
 } 

 else{
      echo "There was an error uploading the file, please try again!";
   }
   ?&gt;
</code></pre>

<p>i have a folder named uploads in the www directory of wamp folder.and i need to store the uploaded file in this folder.</p>

<p>but when i run the android program it shows error message as</p>

<pre><code>"java.net.Connect Exception: localhost/127.0.0.1:80 - Connection refused"
</code></pre>

<p>can anybody give me a solution for this and let me know my coding are enough to achieve my target.  thanks in advance</p>
