Error when attempting to PUT file to URL with Node request

2.3k Views Asked by At

I am trying to PUT a file to an S3 pre-signed URL. Doing so with bash/cURL works fine but with Node I am getting the following error:

Error: write EPIPE
    at WriteWrap.onWriteComplete [as oncomplete] (node:internal/stream_base_commons:94:16) {
  errno: -32,
  code: 'EPIPE',
  syscall: 'write'
}

Here is the code

const fs = require('fs');
const request = require('request');

stream = fs.createReadStream('/tmp/file');
r = request.put('https://s3.eu-west-2.amazonaws.com/bucketname/path?X-Amz-Content-Sha256=....&...');
stream.pipe(r).on('error', function(err) {
   console.log(err);
});
1

There are 1 best solutions below

0
Yilmaz On

EPIPE means that the writing request failed because the other end closed the connection. Looks like there might be some additional settings required inorder to work with amazon s3. I know that curl has native support for multipart/form-data. You can use this library to create readable multipart/form-data streams.

https://nicedoc.io/form-data/form-data

  • Or you can use third party libraries to send data

https://www.npmjs.com/package/s3-upload-stream

https://www.npmjs.com/package/streaming-s3