Source:
private void uploadFileUsingHTTPClient(Operation operation, String uploadURL, final String userName, final String password, String fileLocation) throws AndroidAgentException { int serverResponseCode; HttpURLConnection connection = null; DataOutputStream dataOutputStream = null; final String lineEnd = "\r\n"; final String twoHyphens = "--"; final String boundary = "*****"; int bytesRead, bytesAvailable, bufferSize; byte[] buffer; int maxBufferSize = 1024 * 1024; File selectedFile = new File(fileLocation); final String fileName = selectedFile.getName(); FileInputStream fileInputStream = null; try { fileInputStream = new FileInputStream(selectedFile); URL url = new URL(uploadURL); connection = getHttpConnection(url, userName, password); connection.setRequestProperty("uploaded_file", fileLocation); dataOutputStream = new DataOutputStream(connection.getOutputStream()); dataOutputStream.writeBytes(twoHyphens + boundary + lineEnd); dataOutputStream.writeBytes("Content-Disposition: form-data; name=\"file\";filename=\"" + fileName + "\"" + lineEnd); dataOutputStream.writeBytes(lineEnd); bytesAvailable = fileInputStream.available(); bufferSize = Math.min(bytesAvailable, maxBufferSize); buffer = new byte[bufferSize]; bytesRead = fileInputStream.read(buffer, 0, bufferSize); while (bytesRead > 0) { dataOutputStream.write(buffer, 0, bufferSize); bytesAvailable = fileInputStream.available(); bufferSize = Math.min(bytesAvailable, maxBufferSize); bytesRead = fileInputStream.read(buffer, 0, bufferSize); } dataOutputStream.writeBytes(lineEnd); dataOutputStream.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd); serverResponseCode = connection.getResponseCode(); Log.i(TAG, "Server Response is: " + connection.getResponseMessage() + ": " + serverResponseCode); if (serverResponseCode == 200) { operation.setStatus(resources.getString(R.string.operation_value_completed)); operation.setOperationResponse("File uploaded from the device completed ( " + fileName + " )."); } } catch (IOException e) { handleOperationError(operation, fileTransferExceptionCause(e, fileName), e, resources); } finally { if (connection != null) { connection.disconnect(); } cleanupStreams(null, null, fileInputStream, null, null, null, null, dataOutputStream); } }

Target:
private void uploadFileUsingHTTPClient(Operation operation, String uploadURL, final String userName, final String password, String fileLocation) throws AndroidAgentException { int serverResponseCode; HttpURLConnection connection = null; DataOutputStream dataOutputStream = null; final String lineEnd = "\r\n"; final String twoHyphens = "--"; final String boundary = "*****"; int bytesRead, bytesAvailable, bufferSize; byte[] buffer; int maxBufferSize = 1024 * 1024; File selectedFile = new File(fileLocation); final String fileName = selectedFile.getName(); FileInputStream fileInputStream = null; try { fileInputStream = new FileInputStream(selectedFile); URL url = new URL(uploadURL); connection = getHttpConnection(url, userName, password); connection.setRequestProperty("uploaded_file", fileLocation); dataOutputStream = new DataOutputStream(connection.getOutputStream()); dataOutputStream.writeBytes(twoHyphens + boundary + lineEnd); dataOutputStream.writeBytes("Content-Disposition: form-data; name=\"file\";filename=\"" + fileName + "\"" + lineEnd); dataOutputStream.writeBytes(lineEnd); bytesAvailable = fileInputStream.available(); bufferSize = Math.min(bytesAvailable, maxBufferSize); buffer = new byte[bufferSize]; bytesRead = fileInputStream.read(buffer, 0, bufferSize); while (bytesRead > 0) { dataOutputStream.write(buffer, 0, bufferSize); bytesAvailable = fileInputStream.available(); bufferSize = Math.min(bytesAvailable, maxBufferSize); bytesRead = fileInputStream.read(buffer, 0, bufferSize); } dataOutputStream.writeBytes(lineEnd); dataOutputStream.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd); serverResponseCode = connection.getResponseCode(); if (Constants.DEBUG_MODE_ENABLED) { Log.d(TAG, "Server Response is: " + connection.getResponseMessage() + ": " + serverResponseCode); } if (serverResponseCode == 200) { operation.setStatus(resources.getString(R.string.operation_value_completed)); operation.setOperationResponse("File uploaded from the device completed ( " + fileName + " )."); } } catch (IOException e) { handleOperationError(operation, fileTransferExceptionCause(e, fileName), e, resources); } finally { if (connection != null) { connection.disconnect(); } cleanupStreams(null, null, fileInputStream, null, null, null, null, dataOutputStream); } }