원격 메서드를 사용하여 동적으로 생성 된 pdf 파일을 다운로드하려는 경우 해당 파일이 특정 경로에 존재하며 반환 유형 "파일"을 사용하고 있습니다. 내 구현은 다음과 같습니다원격 메서드를 사용하여 pdf 다운로드
customer.downloadFile = function downloadFile(userId, cb){
var reader = fs.createReadStream(__dirname + '/../document.pdf');
cb(null, reader, 'application/pdf');
};
customer.remoteMethod(
'downloadFile',
{
isStatic: true,
accepts: [
{arg: 'id', type: 'string', required: true}
],
returns: [
{ arg: 'body', type: 'file', root: true },
{ arg: 'Content-Type', type: 'string', http: { target: 'header' } }
],
http: {path: '/:id/downloadFile', verb: 'get'}
}
);
위의 코드 문제는 아름다운 pdf 파일 컨테이너 대신 파일에 다음과 같은 오류의 표시하지만 브라우저가 표시되고 있다는 점이다 :
지적하십시오 코드의 문제점과 수정 방법에 관해서 이 url에서 리드를 얻으십시오 : https://github.com/strongloop/loopback-swagger/issues/34
내용 - 처리 : 인라인; filename = "filename.pdf"// 헤더에 들어가기 – MMK