title: OutOfMemory on big HTTP MultipartRequestEntity via apache HttpClient 3.1
body: <p>I'm actually trying to upload a file (>5M) using apache HttpClient 3.1 via MultipartRequestEntity with java 1.4 in a low memory environment, so increasing java heap is not possible</p>
  
  <p>I have a file splitted in many parts, I just need to append all the data of each part into the request, I could get the file without splitting too</p>
  
  <p>The real problem is that the request I'm building, is producing the memory to overflow, is there any way to avoid this and be able to send this request at once?</p>
  
  <p>This is what I actually have, I would need to append the bytes to the part (a kind of part[0].write(data)), or get a stream to write it without loading into the memory, I don't know if it is actually possible</p>
  
  <pre><code>    HttpClient client = new HttpClient();
      PostMethod post = new PostMethod(url);
  
      post.setContentChunked(true);
  
      try {
          Part[] parts = new Part[fileNames.size()];
  
          String fileName = "sample.pdf";
  
          for(int i = 0; i&lt;fileNames.size();i++){
              File file = Util.getFile(fileNames.get(i));
              FileInputStream is = new FileInputStream(file);
              byte[] fileBytes = IOUtils.toByteArray(is);
              parts[i] = new FilePart("file", new ByteArrayPartSource(fileName, fileBytes) , "application/octet-stream", post.getRequestCharSet()); 
              is.close();
              is = null;
              fileBytes = null;
          }
  
       MultipartRequestEntity requestEntity = new MultipartRequestEntity(parts, post.getParams());
  
       post.setRequestEntity(requestEntity);
  
  
       int statusCode = client.executeMethod(post);
  </code></pre>
  
  <p>Another possibility is with HttpUrlConnection writing a BufferedWriter, but this will also give OutOfMemory when writing on it</p>