title: How can I improve my video upload currently crashes the app from out of memory usage
body: <p>I currently am uploading videos from my app (android) which causes crashes in the application, trying to figure out how to make it efficient on both ends, the app and server side... At the end of the day it does upload the video but crashes either the app or the server depending which one runs out of memory.</p>
  
  <p>Stack - Java, retrofit, Node.js, knox, heroku, amazonS3</p>
  
  <p>For client side android: (retrofit, java):</p>
  
  <p>rest File:</p>
  
  <pre><code>@Multipart
          @POST("/addMedia")
          public void addMedia(
                  @Part("name") String name,
                  @Part("categ") String category,
                  @Part("desc") String desc,
                  @Part("creatorId") String creatorId,
                  @Part("isItAPicture") String isItAPicture, //if true it is a picture
                  @Part("mediaFile") TypedFile mediaFile,
                  Callback&lt;UserResponse&gt; callback);
  </code></pre>
  
  <p>Create Class File:</p>
  
  <pre><code>  ApiManager.getAsyncApi().addMedia(title, categ, descr, creatorId, String.valueOf(isPictureNotvideo), media, new Callback&lt;UserResponse&gt;() {
              @Override
              public void success(UserResponse userResponse, Response response) {
               \
              }
  
              @Override
              public void failure(RetrofitError error) {
  throw error;
              }
          });
  </code></pre>
  
  <p>The server side (Node.js, heroku, AmazonS3, knox module)</p>
  
  <pre><code>var s3 = knox.createClient({
      key: config.amazonS3.key,
      secret: config.amazonS3.secret,
      bucket:config.amazonS3.bucketMedia
  });
  
  
  
  
  
  
  function setupAndCreateMedia ( cb) {
      if(req.files &amp;&amp; req.files.mediaFile) {
          console.log("Received file:\n" + JSON.stringify(req.files));
          //add p for pics will do v for vids
          videoID = "v" + path.basename(req.files.mediaFile.path);
          tmp_path = req.files.mediaFile.path;
          targetPathSmall = './public/img/media/' + videoID;
          videoConvert = req.files.mediaFile.name;
          var video = req.files.mediaFile;
          var s3Headers = {
              'Content-Type': video.type,
              'x-amz-acl': 'public-read'
          };
          //console.log('stdout:', stdout, targetPathSmall)
          s3.putStream(targetPathSmall, videoID, s3Headers, function(err, s3response){
          //handle, respond
              if(err) { 
                  console.log(err);
              } else {
                  console.log("saved to S3");
                  //console.log(s3response);
                  cb(null, videoID);
              }
          });
      } else {
          videoID = "";
          cb(null, videoID);
      }
  }
  </code></pre>
  
  <p>This is the crash message on android:</p>
  
  <pre><code>Caused by: java.lang.OutOfMemoryError: Failed to allocate a 48298892 byte allocation with 16777216 free bytes and 44MB until OOM
  </code></pre>