我打算使用遠程方法下載動態生成的pdf文件,該文件存在於特定路徑中,並且正在使用返回類型「file」。我的實現是:使用遠程方法下載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