axios({
method: 'get',
url: `https://demo.docusign.net/restapi/v2/accounts/{AccountID}/envelopes/{ID}/documents/1`,
headers: {
'X-DocuSign-Authentication': JSON.stringify({
"Username": docusign.username,
"Password": docusign.password,
"IntegratorKey": docusign.integratorKey
}),
'Content-Type': 'application/json'
},
}).then(response => {
fs.writeFileSync('./i.pdf', response.data, {encoding: 'binary'})
}).catch(console.log)
使用上面的代码,我无法保存正确的文件,请问您对此有何帮助
答案 0 :(得分:1)
Arjun我找到了解决方案,请检查以下代码。
let docuResponce = axios({
method: 'get',
url:`https://demo.docusign.net/restapi/v2/accounts/{AccountID}/envelopes/{ID}/documents/1`,
headers: {
'X-DocuSign-Authentication': JSON.stringify({
"Username": docusign.username,
"Password": docusign.password,
"IntegratorKey": docusign.integratorKey
}),
'Content-Type': 'application/pdf'
},
responseType: 'stream'
});
var fs = require('fs');
var path = require('path');
// file name
var filename = envelopID + '_' + docusign.accountID + '.pdf';
var tempFile = path.resolve(__dirname, filename); // file path
// generate a file stream
docu.data.pipe(fs.createWriteStream(tempFile));
docu.data.on('end', () => {
// file has been download
res.status(200).json({ success: 'true', data: '' });
});
docu.data.on('error', (err) => {
// error in download
res.status(200).json({ success: 'false', data: '' });
});
答案 1 :(得分:0)