【发布时间】:2017-08-16 18:47:02
【问题描述】:
我有网址:http://localhost:9999/file/bongda.PNG
我使用 nodejs 为公共文件服务:
application.use(express.static(path.join(__dirname, 'uploads')));
和
application.get('/file/:name', function (req, res, next) {
var options = {
root: __dirname + '/uploads/',
dotfiles: 'deny',
headers: {
'x-timestamp': Date.now(),
'x-sent': true
}
};
console.log('Express server listening downloads ');
var fileName = req.params.name;
res.type('png');
res.sendFile(fileName, options, function (err) {
if (err) {
next(err);
} else {
console.log('Sent:', fileName);
}
});
});
我想从 url 下载文件
我使用<a href="window.location.href='http://localhost:9999/file/bongda.PNG'">123123</a>
或
<a href="http://localhost:9999/file/bongda.PNG">123123</a>
但它没有成功。 请帮帮我?
【问题讨论】:
-
错误信息是什么?
-
没有消息抛出
-
关于错误的图片
-
您对图片的请求的 http-answer 是什么?