title: image uploading returns a File not found exception
body: <p>I am trying to upload an image from Android client to a .net web API. I can not figure out what's going wrong with the client code.</p>
  
  <p><strong>Client code</strong>    </p>
  
  <pre><code>@Override
  protected String doInBackground(String... strings) {
      try {
          String lineEnd = "\r\n";
          String twoHyphens = "--";
          String boundary = "*****";
          int bytesRead, bytesAvailable, bufferSize;
          byte[] buffer;
          int maxBufferSize = 1024 * 1024;
          File file = new File(imagePath);
  
          URL url = new URL(strings[0]);
  
          HttpURLConnection connection = (HttpURLConnection) url.openConnection();
          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("Authorization", "bearer "+ LoginActivity.token);
          connection.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary);
  
          DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream());
  
          Log.d("file path", file.getPath() );
  
          outputStream.writeBytes(twoHyphens + boundary + lineEnd);
          //outputStream.writeBytes(lineEnd);
          outputStream.writeBytes("Content-Disposition: form-data; name=\"ProfilePic\"; filename=\""+ file.getAbsolutePath() + "\"" + lineEnd);
          outputStream.writeBytes("Content-Type: image/png" + lineEnd);
  
          FileInputStream fileInputStream;
          fileInputStream = new FileInputStream(file.getAbsoluteFile());
          bytesAvailable = fileInputStream.available();
          bufferSize = Math.min(bytesAvailable, maxBufferSize);
          buffer = new byte[bufferSize];
  
          // Read file
          bytesRead = fileInputStream.read(buffer, 0, bufferSize);
  
          while (bytesRead &gt; 0) {
              try{
                  outputStream.write(buffer, 0, bufferSize);
              } catch (OutOfMemoryError e) {
                  e.printStackTrace();
                  Log.d("Exception occured", "Out of memory");
                  return "out of memory";
              }
              bytesAvailable = fileInputStream.available();
              Log.d("output stream", outputStream+"");
              bufferSize = Math.min(bytesAvailable, maxBufferSize);
              bytesRead = fileInputStream.read(buffer, 0, bufferSize);
          }
          outputStream.writeBytes(lineEnd);
          outputStream.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);
  
          Log.d("Response image upload", connection.getResponseCode()+"");
  
          /*** output printing ***/
          BufferedReader _reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
          String line = "";
          StringBuilder response = new StringBuilder();
  
          while( (line = _reader.readLine()) != null ) {
              response.append(line);
          }
  
          String data = response.toString();
  
          Log.d("Output data", data);
          /****/
  
      } catch (MalformedURLException e) {
          e.printStackTrace();
      } catch (IOException e) {
          e.printStackTrace();
      }
      return null;
  }
  </code></pre>
  
  <p><strong>Server code</strong></p>
  
  <pre><code>[HttpPost]
  public IHttpActionResult SaveImage()
  {
   var httpRequest = HttpContext.Current.Request;
   HttpPostedFile file = httpRequest.Files["ProfilePic"];
  
   if (file == null)
     throw new EmptyObjectException(ErrorMessageTypes.EmptyObject, jobSeekerId);
  
   // saving the image
  }
  </code></pre>
  
  <p>What actually is happening is- somehow the image is not being sent properly from client. It would be great to have your help on this context. Thanks</p>