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

5
  • is fs what you're looking for? nodejs.org/api/fs.html you already tagged your question with it so is there something else? Commented Jul 17, 2020 at 5:56
  • I'm using the older version of node - 6.10.0, will it work with the link you sent? Commented Jul 17, 2020 at 5:59
  • 1
    Yes, fs has been part of node from the start. nodejs.org/docs/latest-v6.x/api/fs.html Commented Jul 17, 2020 at 6: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? Commented Jul 17, 2020 at 6:46
  • fetch a file directly and download it in a browser Commented Jul 17, 2020 at 8:23

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.