javascript - Unable to createWriteStream to save downloaded file -


i have function in nw.js app downloads bunch of files server , saves them in folder chosen user names sent server. not know names of files in advance - urls using randomly-generated strings have gotten server, , server looking each hash see file corresponds to.

var regexp = /filename=\"(.*)\"/gi;  media_urls.foreach(function(url) {     var req = client.request(options, function(res) {         var file_size = parseint(res.headers['content-length'], 10);         var content_disposition = res.headers['content-disposition'];         var name = regexp.exec(content_disposition)[1];         var path = path.join(save_dir, name);          var file = fs.createwritestream(path);         file.on('error', function(e) {             console.log(e);             req.abort();         });          res.on('data', function(chunk) {             file.write(chunk);         });          res.on('end', function() {             file.end();         });     });     req.on('error', function(e) {         console.log(e);     });     req.end(); }); 

i keep getting enoent errors when code runs. doesn't make sense because file supposed created now, of course doesn't exist!

why getting error instead of having file downloaded?

the file names coming server had :s in them, valid filename character on linux ext4, not on windows ntfs.

changing

var name = regexp.exec(content_disposition)[1]; 

to

var name = regexp.exec(content_disposition)[1].replace(':', '-'); 

solved particular problem.


Popular posts from this blog