title: Send files from android device to server?
body: <p>How to send all files from sdcard to server i can push file from device to server through this
  Code :</p>
  
  <pre><code>public void btnclick(View v) {
  
          String pathToOurFile = "/mnt/sdcard/" + "q.3gp";
          String urlServer = "http://www.google.com/upload.php";
          String lineEnd = "\r\n";
          String twoHyphens = "--";
          String boundary = "*****";
          int bytesRead, bytesAvailable, bufferSize;
          byte[] buffer;
          int maxBufferSize = 1 * 1024 * 1024;
  
          try {
  
              FileInputStream fileInputStream = new FileInputStream(new File(
                      pathToOurFile));
  
              URL url = new URL(urlServer);
              connection = (HttpURLConnection) url.openConnection();
  
              // Allow Inputs &amp; Outputs
              connection.setDoInput(true);
              connection.setDoOutput(true);
              connection.setUseCaches(false);
              connection.setRequestMethod("POST");
              connection.setRequestProperty("Connection", "Keep-Alive");
              connection.setRequestProperty("ENCTYPE", "multipart/form-data");
              connection.setRequestProperty("Content-Type",
                      "multipart/form-data;boundary=" + boundary);
              connection.setRequestProperty("uploaded_file", "gopivideo");
              outputStream = new DataOutputStream(connection.getOutputStream());
              outputStream.writeBytes(twoHyphens + boundary + lineEnd);
              outputStream
                      .writeBytes("Content-Disposition: form-data; name=\"sample\";filename=\""
                              + pathToOurFile + "\"" + lineEnd);
              outputStream.writeBytes(lineEnd);
  
              bytesAvailable = fileInputStream.available();
              bufferSize = Math.min(bytesAvailable, maxBufferSize);
              buffer = new byte[bufferSize];
  
              // Read file
              bytesRead = fileInputStream.read(buffer, 0, bufferSize);
  
              while (bytesRead &gt; 0) {
                  outputStream.write(buffer, 0, bufferSize);
                  bytesAvailable = fileInputStream.available();
                  bufferSize = Math.min(bytesAvailable, maxBufferSize);
                  bytesRead = fileInputStream.read(buffer, 0, bufferSize);
              }
  
              outputStream.writeBytes(lineEnd);
              outputStream.writeBytes(twoHyphens + boundary + twoHyphens
                      + lineEnd);
  
              // Responses from the server (code and message)
              int serverResponseCode = connection.getResponseCode();
              String serverResponseMessage = connection.getResponseMessage();
  
              Toast.makeText(getApplicationContext(),
                      serverResponseCode + "," + serverResponseMessage,
                      Toast.LENGTH_LONG).show();
  
              fileInputStream.close();
              outputStream.flush();
              outputStream.close();
          } catch (Exception ex) {
              // Exception handling
          }
      }
  }
  </code></pre>
  
  <p>This is working cool for uploading any type of file to server with single push
  but what is need is to loop all files in sdcard and send one by one.
  Thank you</p>