'createReadStream without path

I'm new to programming and web development, and even I'm not native English speaker so my explanation might be hard to understand.

I'm using aws sdk, aws s3, apollo server, apollo client, react and node when file is sending to a apollo server from a client, a server destructure file to create readable stream so I can upload file to s3. in node filesystem module docs fs.createReadStream method need path but, my code works without path

I just did createReadStream() without any argument. And it works fine so I can upload the file to s3

let { createReadStream, filename, mimetype, encoding } = await file;
let stream = createReadStream();

// don't mind Bucket field
s3.upload({
  Bucket: 'myBucket',
  Key: 'images/' + filename,
  Body: stream,
  ContentType: mimetype
});

Why this works without path argument? Am I missing something?



Solution 1:[1]

try this.

let { createReadStream, filename, mimetype, encoding } = await file;
let stream = createReadStream();

// don't mind Bucket field
s3.upload({
  Bucket: 'myBucket',
  Key: 'images/' + filename,
  Body: createReadStream(),
  ContentType: mimetype
});

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Miguelangel Rojas