Guest User

Untitled

a guest
Jul 16th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. const newfilename = 'foo.csv'
  2.  
  3. // Set the options/headers that we will pass to sendFile()
  4. var options = {
  5. root: __dirname + '/uploads',
  6. dotfiles: 'deny',
  7. headers: {
  8. 'x-timestamp': Date.now(),
  9. 'x-sent': true,
  10. 'Content-type': 'text/csv; charset=utf-8',
  11. 'Content-disposition': `attachment;filename="foo.csv"`
  12. }
  13. };
  14.  
  15. // This will actually send the file to the browser as a direct download
  16. response.sendFile(newfilename, options, (err) => {
  17. if (err) {
  18. return res.status(500).send(err)
  19. }
  20.  
  21. console.log(`Sending file: ${csvFilePath}`);
  22. });
  23.  
  24. app.use(cors({
  25. origin: 'https://www.example.com',
  26. methods: 'POST'
  27. }))
  28.  
  29. // allow files to be served from here
  30. app.use(express.static(path.join(__dirname, 'uploads')))
Add Comment
Please, Sign In to add comment