Below is the code from React side
import axios from 'axios'
import fileDownload from 'js-file-download'
axios.post(SERVER_URL+ 'schools/search/download', { 'action' : 'download' }, options)
.then((res) => {
console.log('res.data is ',res.data);
fileDownload(res.data, 'search_no_results.csv')
})
/below is the code from Sails side
let file = require('path').resolve('noresults.txt');
const fs = require('fs');
if(fs.existsSync('noresults.txt'))
{
res.setHeader('Content-disposition', 'attachment; filename=' + 'search_no_results.csv');
let filestream = fs.createReadStream(file);
filestream.pipe(res);
}else{
res.json({error : "File not Found"});
}
references:
-- Living Mobile --: Sails + React . How To A File >>>>> Download Now
ReplyDelete>>>>> Download Full
-- Living Mobile --: Sails + React . How To A File >>>>> Download LINK
>>>>> Download Now
-- Living Mobile --: Sails + React . How To A File >>>>> Download Full
>>>>> Download LINK 1Z