0
그래, 내가하려고하는 것은 사용자가 클릭 할 때 파일을 사용자의 디스크에 저장하는 것이다. 여기 코드, 아약스입니다 : 내 서버 파일에아약스와 노드를 사용하여 디스크에 파일을 다운로드하는 방법
$('.cv_download').on('click',function(){
var fileName = $(this).text();
console.log(fileName)
var temp = {"file" : fileName}
console.log(temp);
console.log(JSON.stringify(temp))
$.ajax({
url: '/download-cv-file',
type: 'POST',
data: {fileSend:JSON.stringify(temp)},
dataType: 'json'
});
})
난이 :
app.post('/download-cv-file', function(req, res){ services.downloadFile(req,res); });
하는 화재 :
var downloadFile = function(req,res){
console.log('From services')
console.log(req.body.fileSend)
var p_file = JSON.parse(req.body.fileSend);
console.log(p_file);
console.log('The file we look for is ' + p_file.file);
var file = 'services/cvs/'+p_file.file+'';
console.log('The file is ' + file);
res.download(file);}
어떤 아이디어가? 고맙습니다!
문제가 무엇입니까 : 여기
이에 대한 좋은 참조가? –파일을 저장하지 않으려면 메시지가 표시되지 않습니다. – Niko
코드에 프롬프트가 없습니다. 그것은 콘솔에 무엇이든 쓸 수 있습니까? – ABri