0
아약스 게시물 요청에 대한 응답으로 파일을 다운로드 할 수 없습니다.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