0

I have a file which I download to our desktop for all type of operating system like windows, linux, mac etc. The below code I am using for download it from third server to my serve folder:

var fileticketID = req.params.fileticketID;
var download = function(uri, filename, callback){
BASE.request.head(uri, function(err, res, body){BASE.request(uri).pipe(BASE.FS.createWriteStream('public/images/'+filename)).on('close', function(err) {
var stats = BASE.FS.statSync('public/images/'+filename);
var fileSizeInBytes = stats["size"];
var fields = {filename : filename,size:fileSizeInBytes};
var fieldsData = new downloadFile(fields);
fieldsData.save(function(err, data){
        if(!err)
        {
            if(fileSizeInBytes==0)
            {
                resMain.send('error');
            }
            else
            {
            resMain.send(filename);
            }
        //console.log('successfully saved -- ');
        }
        else
        {
            resMain.send('error');
        //console.log('sorry error ', err);
        }
    });
});

Now I want to file is also downloaded in desktop

Sumit Aggarwal
  • 831
  • 2
  • 16
  • 29
  • I'm not very clear with the last sentence. "Now i want to file is also downloaded in desktop". What do you mean? – James Aug 01 '16 at 10:55
  • i want to download that file from server to local system – Sumit Aggarwal Aug 01 '16 at 10:56
  • like if i have a file in my server folder http://example.com/images/filename then i want to download that file in local system desktop – Sumit Aggarwal Aug 01 '16 at 10:58
  • Possible duplicate of [How to download a file with Node.js (without using third-party libraries)?](http://stackoverflow.com/questions/11944932/how-to-download-a-file-with-node-js-without-using-third-party-libraries) – mansoor.khan Aug 01 '16 at 11:21
  • is there any way to get local system desktop path in node.js? – Sumit Aggarwal Aug 01 '16 at 11:24
  • no that is different that is specific for directory but in my case i want to download it local system like c://desktop etc – Sumit Aggarwal Aug 01 '16 at 11:40
  • You want to download the file from your local system or download the file to local system? If it is to local system, give the path to it when you download from browser. If it is from local system, your nodejs should be running from it and you can give absolute path to the file. – James Aug 01 '16 at 11:51
  • i want to download the file from server to local system – Sumit Aggarwal Aug 01 '16 at 11:59
  • If that's the case, what @steady_daddy commented should work for you. – James Aug 01 '16 at 15:55

0 Answers0