title: Uploading large files to Amazon S3 creates two copies after two minutes
body: <p>I am trying to upload large files (50 to 60 MB) to amazon S3 bucket from a server written in NodeJS. The server receives the file(s) from a ReactJS frontend. I came across the problem that there are two copies of same file being uploaded to the S3 bucket (although the timestamp differs by two minutes).
  see the screenshot from my bucket</p>
  
  <p><img src="https://i.stack.imgur.com/53IGC.png" alt=""></p>
  
  <p>here's my api written in expressJS/NodeJS :</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>app.post('/myAPI', (req, res) =&gt; {
    
    console.log("------------------------------- In builds API - post request -------------------------------");
    
      console.log(req.method);
      console.log("This device is Android");
      let File = req.files.file;
  
      //appending the date object to the file name
      let date = JSON.stringify(new Date()).replace(/\"/g, "").replace(/:/g, "-");
      let index = File.name.lastIndexOf(".");
      let newname = [File.name.slice(0, index), date, File.name.slice(index)].join('');
      newname = req.body.project + "/" + newname;
      
      let busboy = new Busboy({ headers: req.headers });
      
      //this event is fired when the data is successfully uploaded
      eventEmitter.on('data_uploaded', function() {
        res.end(`done !!!!!!!!!!!!!!!!!!`);
      });
  
      busboy.on('finish', function( ) {
        
        let s3bucket = new AWS.S3({
          accessKeyId: IAM_USER_KEY,
          secretAccessKey: IAM_USER_SECRET,
          Bucket: BUCKET_NAME
        });
  
        s3bucket.createBucket(function () {
          console.log("In create bucket method");
          var params = {
            Bucket: BUCKET_NAME,
            Key: newname,
            Body: File.data
          };
          s3bucket.upload(params, function (err, data) {
            if (err) {
              console.log('error in callback');
              console.log(err);
            }
            
            console.log(data);
            
            eventEmitter.emit('data_uploaded'); 
          });
        });
  
      });
      
      //piping the request to writable stream busboy
      req.pipe(busboy);
    }
  
  });</code></pre>
  </div>
  </div>
  </p>
  
  <p>here's what my console looks like</p>
  
  <p><img src="https://i.stack.imgur.com/yxJ3x.png" alt="">.. <strong>everything two times</strong>.</p>
  
  <p>I am checking into my browser's network tab and the request sent is <strong>only one</strong>..</p>
  
  <p>and though the response is received only once as this:</p>
  
  <p><img src="https://i.stack.imgur.com/2y3Py.png" alt=""></p>
  
  <p>What am I doing wrong.. please help me out here !
  Thanks a million in advance.</p>
  
  <p>( I wrote this API using <a href="https://medium.com/@Keithweaver_/uploading-a-file-to-amazon-web-services-aws-s3-bucket-with-node-js-133b0a1af2b9" rel="nofollow noreferrer">this tutorial by Keith Weaver</a> ).</p>