Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const newfilename = 'foo.csv'
- // Set the options/headers that we will pass to sendFile()
- var options = {
- root: __dirname + '/uploads',
- dotfiles: 'deny',
- headers: {
- 'x-timestamp': Date.now(),
- 'x-sent': true,
- 'Content-type': 'text/csv; charset=utf-8',
- 'Content-disposition': `attachment;filename="foo.csv"`
- }
- };
- // This will actually send the file to the browser as a direct download
- response.sendFile(newfilename, options, (err) => {
- if (err) {
- return res.status(500).send(err)
- }
- console.log(`Sending file: ${csvFilePath}`);
- });
- app.use(cors({
- origin: 'https://www.example.com',
- methods: 'POST'
- }))
- // allow files to be served from here
- app.use(express.static(path.join(__dirname, 'uploads')))
Add Comment
Please, Sign In to add comment