Please make sure you have the required Web Services for Posting.
Just pass the file and url of server and the following should run.
try{
int maxBufferSize=1024*1024;
File file = new File(YourPathToFile);
String fileName = file.getName();
URL url = new URL(YourUrlServer);
connection = (HttpURLConnection) url.openConnection();
// Allow Inputs & Outputs
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setUseCaches(false);
// Enable POST method
connection.setRequestMethod("GET");
connection.setRequestProperty("Connection", "Keep-Alive");
connection.setRequestProperty("Content-Type", "multipart/form-data;boundary="+boundary);
connection.setChunkedStreamingMode(maxBufferSize);
outputStream = new DataOutputStream( connection.getOutputStream() );
fileInputStream = new FileInputStream(file);
outputStream.writeBytes(twoHyphens + boundary + lineEnd);
outputStream.writeBytes("Content-Disposition: form-data; name=\"strAuthKey\"" + lineEnd);
outputStream.writeBytes(lineEnd);
outputStream.writeBytes(SoapRequestProcessor.authKey());//authentication key
outputStream.writeBytes(lineEnd);
outputStream.writeBytes(twoHyphens + boundary + lineEnd);
outputStream.writeBytes("Content-Disposition: form-data; name=\"mediaName\"" + lineEnd);
outputStream.writeBytes(lineEnd);
outputStream.writeBytes(fileName); //file.lastModified()+"_"+
outputStream.writeBytes(lineEnd);
outputStream.writeBytes(twoHyphens + boundary + lineEnd);
outputStream.writeBytes("Content-Disposition: form-data; name=\"uploadedfile\";filename=\"IMAGEFILE\"" + lineEnd);
outputStream.writeBytes(lineEnd);
bytesAvailable = fileInputStream.available();
bufferSize = Math.min(bytesAvailable, maxBufferSize);
buffer = new byte[bufferSize];
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
while (bytesRead > 0)
{
outputStream.write(buffer, 0, bufferSize);
bytesAvailable = fileInputStream.available();
bufferSize = Math.min(bytesAvailable, maxBufferSize);
buffer = new byte[bufferSize];
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
}
outputStream.writeBytes(lineEnd);
outputStream.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);
fileInputStream.close();
outputStream.close();
Log.d("RESPONSE","--"+connection.getResponseMessage());
}
catch (Exception e) {
Log.i("Exception: ",e.toString());
// TODO: handle exception
}