How to upload byte array (Image) to php webservice using POST method with android application?
===

I have used this method to upload image to web service . Here I passed Image Uri to upload image. But I need a method where I shall pass Byte Array to upload image. The code, I used to upload image is given below.

    public static ResponseFromServer upload(Uri imageUri, Context c) {
		HttpURLConnection connection = null;
		DataOutputStream outputStream = null;
		DataInputStream inputStream = null;

		ResponseFromServer response = new ResponseFromServer();
		try {
		c=image&m=upload&userId="+Constants.logedInUserId+"&&accessKey="+Constants.ACCESS_KEY;

		String urlServer = Constants.SERVER_URL + "/image_upload?version="
				+ "1.0" + "&email=" + URLEncoder.encode(Constants.email)
				+ "&proc_date=" + URLEncoder.encode(Constants.proc_date)
				+ "&access_key=" + URLEncoder.encode(Constants.ACCESS_KEY)
				+ "&original_image_name="
				+ URLEncoder.encode(getdate() + ".jpg");

		Log.e("Image Upload API TKB  ", "" + urlServer);

		String lineEnd = "\r\n";
		String twoHyphens = "--";
		String boundary = "*****";

		int bytesRead, bytesAvailable, bufferSize;
		byte[] buffer;
		int maxBufferSize = 1 * 1024 * 1024;

		
			String[] filePathColumn = { MediaStore.Images.Media.DATA };

			Cursor cursor = c.getContentResolver().query(imageUri,
					filePathColumn, null, null, null);
			cursor.moveToFirst();

			int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
			String filePath = cursor.getString(columnIndex);
			cursor.close();

			// Bitmap yourSelectedImage = BitmapFactory.decodeFile(filePath);

			// Bitmap bm=BitmapFactory.decodeFile(imageUri.getPath());
			FileInputStream fileInputStream = new FileInputStream(new File(
					filePath));

			URL url = new URL(urlServer);
			connection = (HttpURLConnection) url.openConnection();

			// Allow Inputs & Outputs
			connection.setDoInput(true);
			connection.setDoOutput(true);
			connection.setUseCaches(false);

			// Enable POST method
			connection.setRequestMethod("POST");
			connection.setReadTimeout(60000);
			connection.setRequestProperty("Connection", "Keep-Alive");
			connection.setRequestProperty("Content-Type",
					"multipart/form-data;boundary=" + boundary);

			outputStream = new DataOutputStream(connection.getOutputStream());
			outputStream.writeBytes(twoHyphens + boundary + lineEnd);
			outputStream
					.writeBytes("Content-Disposition: form-data; name=\"original_image_bynary\";filename=\""
							+ filePath + "\"" + 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 > 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();
			Log.e("serverResponseCode: ", serverResponseCode + "");
			BufferedReader rd = new BufferedReader(new InputStreamReader(
					connection.getInputStream()));
			StringBuffer sb = new StringBuffer();
			String line;
			while ((line = rd.readLine()) != null) {
				sb.append(line);
			}
			rd.close();

			String responseString = sb.toString();

			JSONObject jsonObject;

			jsonObject = new JSONObject(responseString);

			String status = jsonObject.getString("status");
			String message = jsonObject.getString("msg");
			// String data=jsonObject.getString("data");

			response.setStatus(status);
			response.setMessage(message);
			 
			fileInputStream.close();
			outputStream.flush();
			outputStream.close();
		}
		catch (SocketTimeoutException ste) {
			Log.e("Timeout", "Data not found");
			return null;
		}

		catch (Exception ex) {
			// Exception handling
			response.setMessage("Upload failed. " + ex.getMessage());
			response.setStatus("0");
			ex.printStackTrace();
			return null;
			// Exception e=ex;
		}

		return response;

	}

How do I customize this code where I can pass only Byte array to upload Image. 