title: How can I create a file from S3 object buffer and send it to server
body: <p>I have an API POST endpoint that expects multipart file data. I need to invoke this endpoint whenever a file is uploaded to an S3 bucket.</p>
  <p>Using the below piece of code, I get the content of the file as Buffer in the filedata.Body object.</p>
  <pre><code>const filedata = await s3.getObject(params).promise();
  console.log('CONTENT:', filedata.Body);
  </code></pre>
  <p>As mentioned above, I need to send this content to the POST endpoint as formdata. I am using the following code for it, but it doesn't seem to work.</p>
  <pre><code>const FormData = require('form-data');
  
      const post_body = new FormData();
      post_body.append('file', filedata.Body.toString('utf-8')); // also tried sending buffer directly
   const options = {
            hostname: 'xxxxxamazonaws.com',
            port: 80,
            path: 'xxxxx',
            method: 'POST',
            headers: {
              'Content-Type': 'multipart/form-data'
            }
          };
  
  const req = http.request(options, res =&gt; {
          res.on('data', (chunk) =&gt; {
              data += chunk;
          });
          res.on('end', () =&gt; {
              // some ode
          });
      });
      
      req.on('error', (e) =&gt; {
          console.error(e);
      });
      
      req.write(post_body);
      
      req.end();
  </code></pre>
  <p>The above code errors out by saying that <code>An instance of form data was received where a string or  Uint8Array was expected</code>.</p>
  <p>I have also tried :</p>
  <pre><code>req.write(filedata.Body.toString('utf-8'));
  </code></pre>
  <p>This doesn't seem to work either. I am really stuck at this currently.</p>
  <p>How can I call my API that expects a multipart file using the content received from S3?</p>