0
我無法下載文件來響應ajax發佈請求。通過ajax快速下載文件
$(function(){
$('img.download').click(function() {
var image_path = $(this).attr('class').split(" ")[1]
$.ajax({url:'/download',type:'POST',data:{image_path:image_path}})
})
})
Node.js的代碼
app.post('/download',function(req,res){
//var image_path = req.body.image_path
//var filename = 'new.png'
res.set({
'Content-Type': 'application/octet-stream',
'Content-Disposition': 'attachment;filename=\"new.png\"'
})
//res.set('Content-type', 'image/png')
//var filestream = fs.createReadStream('public/uploads/new.png')
//filestream.pipe(res)
res.download('public/uploads/new.png')
})
我可以通過res.download()下載。它給你什麼錯誤? – user568109 2013-05-02 04:57:48