title: OutputStream out of memory error while sending File to Http
body: <p>Smaller size file are uploaded to server successfully but when it come to larger files the below code throws out of memory error. any solution ?? . Thanks in advance.</p>
  
  <pre><code>public void addFilePart(String fieldName, File uploadFile)
                  throws IOException {
              String fileName = uploadFile.getName();
              writer.append("--" + boundary).append(LINE_FEED);
              writer.append(
                      "Content-Disposition: form-data; name=\"" + fieldName
                              + "\"; filename=\"" + fileName + "\"")
                      .append(LINE_FEED);
              writer.append(
                      "Content-Type: "
                              + URLConnection.guessContentTypeFromName(fileName))
                      .append(LINE_FEED);
              writer.append("Content-Transfer-Encoding: binary").append(LINE_FEED);
              writer.append(LINE_FEED);
              writer.flush();
  
              FileInputStream inputStream = new FileInputStream(uploadFile);
              byte[] buffer = new byte[4096];
              int bytesRead = -1;
              while ((bytesRead = inputStream.read(buffer)) != -1) {
                  outputStream.write(buffer, 0, bytesRead);
              }
              outputStream.flush();
              inputStream.close();
  
              writer.append(LINE_FEED);
              writer.flush();
          }
  </code></pre>