title: Android send file as byte array using json to asp.net api
body: <p>I am trying to send file to SQL server using Asp.net MVC API, the file goes as byte array using <code>Json object</code>,but the API gets a <code>null</code> parameter object instead of the <code>byte array</code> and the other data.
  Is there any way to send the file and the other data to the server?    </p>
  
  <p>Following is the android code</p>
  
  <pre><code>byte[] bytes;
  File file = new File(fileUri.getPath());
  fileName=file.getName();
  int si = (int) file.length();
  bytes = new byte[si];
  
  try {
      BufferedInputStream buf = new BufferedInputStream(new FileInputStream(file));
      buf.read(bytes, 0, bytes.length);
      int y=bytes.length;
      buf.close();
      new UserUploadTask().execute((Void) null);
  } catch (FileNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
  } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
  }
  
  private boolean uploadFile() {
      try {
          String url = String.format("http://site/api/UploadFile");
          URL u = new URL(url);
          HttpURLConnection conn = (HttpURLConnection) u.openConnection();
          conn.setRequestMethod("POST");
          conn.setDoInput(true);
          conn.setDoOutput(true);
          DataOutputStream printout;
          JSONObject j=new JSONObject();
          j.put("mn",serMobileNum);
          j.put("File",arr);
          j.put("title",title);
          j.put("size",size);
          j.put("name",fileName);
          j.put("type",1);
          String msg = j.toString();
          conn.setRequestProperty("Content-Type", "application/json;charset=utf-8");
          conn.setRequestProperty("X-Requested-With", "XMLHttpRequest");
          conn.connect();
          DataOutputStream dos = new DataOutputStream(conn.getOutputStream());
          dos.writeBytes(msg);
          dos.flush();
          dos.close();
  
          BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
          StringBuffer sb = new StringBuffer();
          String line = "";
          Log.i("info", "read");
          while ((line = reader.readLine()) != null) {
              sb.append(line);
          }
          reader.close();
          String FinalString = sb.toString();
          if(FinalString.contains("true")) {
              return true;
          }
          else
              return false;
  
  
      }
      catch (Exception e)
      {
          return false;
      }
  }
  </code></pre>