2017-03-06 3 views
2

내가 노력하고 있어요 : 만 로컬 파일에 대한, 그냥 URL을 사용 (HTTPS를 : // .....)

.post("/getAttachments", (req, res, next) => { 
 
    repository.getAttachments(req.body) 
 
     .then((attachment) => { 
 
     return res.sendFile('https://host.com' + attachment.req.path);    
 
     }) 
 
     .catch(next); 
 
    }) 
 
///clientService: 
 
function getAttachments(params) { 
 
     return $http.post(baseUrl + "/getAttachments", params, {responseType: 'arraybuffer'}).success(function (data) { 
 
     let blob = new Blob([data], {type: 'application/vnd.ms-excel'}); 
 
     saveAs(blob); 
 
     }); 
 
    };

모든 작품. 도와주세요.

답변

3

res.sendFile은 로컬 파일에서만 작동합니다. https://github.com/request/request

  • 당신이 올바른 헤더를 전송하고 일부 오류 처리를 추가해야합니다 : request 모듈을 사용하여

    request('https://host.com' + attachment.req.path).pipe(res); 
    

    : 원격 파일에 대해 당신이 뭔가를해야합니다.

    또 다른 옵션을 보내는 대신 올바른 URL로 사용자를 리디렉션하는 것입니다 :

    res.redirect('https://host.com' + attachment.req.path); 
    

    클라이언트가 중간에 요청을 프록시 서버없이 파일을 다운로드 할 경우

    .

+0

감사합니다. 정말 도움이됩니다. – aaaaaaaaax10