nodejs--将浏览器默认打开的文件变成下载

来源:互联网 发布:linux dump 内存 编辑:程序博客网 时间:2024/06/06 09:27
var express=require("express")var app=express();var fs = require('fs');var path=require("path");app.get("/upload",function(req,res){    var filePath = path.join(__dirname, './');    console.log(filePath)    fs.readFile(filePath+"images/2010191.png", function(err, data){        res.set({            'Content-Type': 'application/octet-stream',  //告诉浏览器这是一个二进制文件            'Content-Disposition': 'attachment; filename=upload.png'  //告诉浏览器这是一个附件要下载是png图片        });        res.end(data)    })    })app.listen(3000,function(){    console.log("server is running")})

阅读全文
0 0
原创粉丝点击