我收到了多个pdf文件,必须从REST-API下载。
在身份验证和连接之后,我尝试使用request-promise下载文件:
const optionsStart = {
uri: url,
method: 'GET',
headers: {
'X-TOKEN': authToken,
'Content-type': 'applcation/pdf'
}
}
request(optionsStart)
.then(function(body, data) {
let writeStream = fs.createWriteStream(uuid+'_obj.pdf');
console.log(body)
writeStream.write(body, 'binary');
writeStream.on('finish', () => {
console.log('wrote all data to file');
});
writeStream.end();
})
请求创建一个pdf (大约1-2MB),但我无法打开它。(Mac Preview显示空白页面和adobe show =>
打开此文档时出错。读取此文档(14)时出现问题。
我没有关于下载文件的API端点的信息。只做这个卷发:
curl -o doc.pdf --header "X-TOKEN: XXXXXX"
http://XXX.XXX/XXX/docs/doc1
我的错误在哪里?
更新:
我在编辑模式下打开文件,文件看起来是这样的:
没有任何经验:-)
https://stackoverflow.com/questions/48752822
复制相似问题