0

How do I fetch a file from local machine with its file name and dowloand the same in Node.js without using third-party libraries?

I have seen this answer similar to this - How to download a file with Node.js (without using third-party libraries)?

but it shows to download using URL, but I need to fetch and download from my local, is it possible ?

node version I'm using is - 6.10.0

Mar1009
  • 721
  • 1
  • 11
  • 27
  • is fs what you're looking for? https://nodejs.org/api/fs.html you already tagged your question with it so is there something else? – crimson589 Jul 17 '20 at 05:56
  • I'm using the older version of node - 6.10.0, will it work with the link you sent? – Mar1009 Jul 17 '20 at 05:59
  • 1
    Yes, fs has been part of node from the start. https://nodejs.org/docs/latest-v6.x/api/fs.html – crimson589 Jul 17 '20 at 06:21
  • Confused. Are you asking how to send a file using your browser from the browser's local hard disk to your server? Or are you asking how your server can fetch a file directly from a remote computer with no browser involved? – jfriend00 Jul 17 '20 at 06:46
  • fetch a file directly and download it in a browser – Mar1009 Jul 17 '20 at 08:23

1 Answers1

1

Not sure why you need "download" from your "local" - you're there already no? If you need to read from your local in order to process or move it somewhere look at the File System module https://nodejs.org/api/fs.html#fs_file_system

var fileStream = fs.createReadStream(filePath);

then you can do something with that file like upload it elsewhere

s3.upload({ Bucket: bucketName, Key: keyName, Body: fileStream});

hth