我正在低于axios呼叫的响应:
Click here to download response (PDF)
当我试图从上面生成PDF时,使用空白页生成链接响应PDF
var fs = require('fs');
fs.writeFileSync("12345678.pdf", response.data, 'binary');
值得称道:
const url = 'url-here'
const headers = {
'headers-here'
};
const axiosConfig = {
headers,
};
axios.get(url, axiosConfig)
.then((response) => {
var fs = require('fs');
fs.writeFileSync("12345678.pdf", response.data, 'binary');
callback(null, response.data);
})
.catch((error) => {
logger.error(error.stack || error.message || error);
callback(error, null);
});
有谁可以帮我生成正确的PDF?
responseType
请求配置中的正确axios
值需要设置为stream
以及pipe
ing响应到流。
axios({
method:'get',
url: 'someUrl',
responseType: 'stream' // #1
})
.then(function (response) {
response.data.pipe(fs.createWriteStream('12345678.pdf')) // #2
});