Showing
1 changed file
with
8 additions
and
7 deletions
... | @@ -93,16 +93,13 @@ router.post('/contact_download', function(req, res, next) { | ... | @@ -93,16 +93,13 @@ router.post('/contact_download', function(req, res, next) { |
93 | 93 | ||
94 | var filename = 'public/upload/contactdownload.xlsx'; | 94 | var filename = 'public/upload/contactdownload.xlsx'; |
95 | fs.exists(filename, function (exists) { | 95 | fs.exists(filename, function (exists) { |
96 | - console.log(exists); | ||
97 | if(exists == true) | 96 | if(exists == true) |
98 | { | 97 | { |
99 | fs.unlink(filename, function (err) { | 98 | fs.unlink(filename, function (err) { |
100 | if (err) throw err; | 99 | if (err) throw err; |
101 | - console.log('file deleted'); | ||
102 | }); | 100 | }); |
103 | } | 101 | } |
104 | }); | 102 | }); |
105 | - | ||
106 | // Create a new instance of a Workbook class | 103 | // Create a new instance of a Workbook class |
107 | var wb = new xl.Workbook(); | 104 | var wb = new xl.Workbook(); |
108 | 105 | ||
... | @@ -135,10 +132,14 @@ router.post('/contact_download', function(req, res, next) { | ... | @@ -135,10 +132,14 @@ router.post('/contact_download', function(req, res, next) { |
135 | ws.cell(i+2, 4).string(rows[i].added_date); | 132 | ws.cell(i+2, 4).string(rows[i].added_date); |
136 | } | 133 | } |
137 | } | 134 | } |
138 | - wb.write('public/upload/contactdownload.xlsx'); | 135 | + wb.write('public/upload/contactdownload.xlsx', (err, stats)=> { |
139 | - var file = __dirname + '/public/upload/contactdownload.xlsx'; | 136 | + if (err){ |
140 | - // console.log(file); | 137 | + throw err; |
141 | - res.download(file); | 138 | + } |
139 | + else { | ||
140 | + res.sendFile(path.join(__dirname, '../public/upload/contactdownload.xlsx')); | ||
141 | + } | ||
142 | + }); | ||
142 | } | 143 | } |
143 | 144 | ||
144 | }); | 145 | }); | ... | ... |
-
Please register or login to post a comment