res.attachment([filename])
This method is used to set Content-disposition header.
Content-Disposition: It is a response header is a header
indicating if the content is expected to be displayed inline in the browser,
that is, as a Web page or as part of a Web page, or as an attachment, that is
downloaded and saved locally.
index.js
'use strict' const express = require('express') const app = express() app.get('/', (req, res) => { res.send('Hello World') }) app.get('/logo', (req, res) => { var fileName = 'https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgpixXs2G_QuEGl0QdCfuZVHIiXFldXDr__UKJEe-09ja_7faZ2yrsCw595igJ0PlAlQwb_dsKy1BwO1GE8PhNb6rRMx_2SSCvxMU9GBoD0pkvIWbuIYc5rivXmLwJ22IlDSML9Cd_WqNJV/s1600/single+level.bmp' res.attachment(fileName) res.send('Sent the logo') }) const port = 3000 app.listen(port, () => console.log(`Application started listening on port ${port}!`));
Run index.js
Open the url 'http://localhost:3000/logo' in browser, it
opens the attached file.
No comments:
Post a Comment