title: Javascript AWS SDK S3 upload method with Body stream generating empty file
body: <p>I'm trying to use the method <strong>upload</strong> from <strong>s3</strong> using a ReadableStream from the module <code>fs</code>. </p>
  
  <p>The <a href="http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#upload-property" rel="noreferrer">documentation</a> says that a ReadableStream can be used at <code>Body</code>param:</p>
  
  <blockquote>
    <p>Body — (Buffer, Typed Array, Blob, String, ReadableStream) Object data.</p>
  </blockquote>
  
  <p>Also the <strong>upload</strong> method description is:</p>
  
  <blockquote>
    <p>Uploads an arbitrarily sized buffer, blob, or stream, using intelligent concurrent handling of parts if the payload is large enough.</p>
  </blockquote>
  
  <p>Also, here: <a href="https://stackoverflow.com/questions/34257185/upload-pdf-generated-to-aws-s3-using-nodejs-aws-sdk">Upload pdf generated to AWS S3 using nodejs aws sdk</a> the @shivendra says he can use a ReadableStream and it works.</p>
  
  <p>This is my code:</p>
  
  <pre><code>const fs = require('fs')
  const S3 = require('aws-sdk/clients/s3')
  
  const s3 = new S3()
  
  const send = async () =&gt; {
    const rs = fs.createReadStream('/home/osman/Downloads/input.txt')
    rs.on('open', () =&gt; {
      console.log('OPEN')
    })
    rs.on('end', () =&gt; {
      console.log('END')
    })
    rs.on('close', () =&gt; {
      console.log('CLOSE')
    })
    rs.on('data', (chunk) =&gt; {
      console.log('DATA: ', chunk)
    })
  
    console.log('START UPLOAD')
  
    const response = await s3.upload({
      Bucket: 'test-bucket',
      Key: 'output.txt',
      Body: rs,
    }).promise()
  
    console.log('response:')
    console.log(response)
  }
  
  send().catch(err =&gt; { console.log(err) })
  </code></pre>
  
  <p>It's getting this output:</p>
  
  <pre><code>START UPLOAD
  OPEN
  DATA: &lt;Buffer 73 6f 6d 65 74 68 69 6e 67&gt;
  END
  CLOSE
  response:
  { ETag: '"d41d8cd98f00b204e9800998ecf8427e"',
    Location: 'https://test-bucket.s3.amazonaws.com/output.txt',
    key: 'output.txt',
    Key: 'output.txt',
    Bucket: 'test-bucket' }
  </code></pre>
  
  <p>The problem is that my file generated at S3 (output.txt) has 0 Bytes.</p>
  
  <p>Someone know what am I doing wrong?</p>
  
  <p>If I pass a buffer on <code>Body</code> it works.</p>
  
  <pre><code>Body: Buffer.alloc(8 * 1024 * 1024, 'something'), 
  </code></pre>
  
  <p>But it's not what I want to do. I'd like to do this using a stream to generate a file and pipe a stream to S3 as long as I generate it.</p>