簡體   English   中英

從Docusign Envelopes API下載Blob

[英]Downloading Blob from Docusign Envelopes API

使用Meteor HTTP,我可以從docusign獲得響應並將其轉換為base64緩沖區。

try {
   const response = HTTP.get(`${baseUrl}/envelopes/${envelopeId}/documents/1`, {
    headers: {
      "Authorization": `bearer ${token}`,
      "Content-Type": "application/json",
    },
  });
   const buffer = new Buffer(response.content).toString('base64');
   return buffer
  } catch(e) {
   console.log(e);
   throw new Meteor.Error(e.reason);
}

然后在客戶端上,我使用FileSaver.jssaveAs為通過此函數從ArrayBuffer創建的blob

function _base64ToArrayBuffer(base64) {
const binary_string =  window.atob(base64);
const len = binary_string.length;
const bytes = new Uint8Array( len );
for (let i = 0; i < len; i++)        {
    bytes[i] = binary_string.charCodeAt(i);
}
return bytes.buffer;
}


// template helper

'click [data-action="download"]'(e, tmpl){
  const doc = this;
  return Meteor.call('downloadPDF', doc, (err, pdf)=>{
    if(err) {
      return notify({
        message: err,
        timeout: 3000,
      })
   }
  const pdfBuffer =  pdf && _base64ToArrayBuffer(pdf);
  console.log(pdfBuffer);
  return  saveAs(new Blob([pdfBuffer], {type: 'application/pdf'}), `docusign_pdf.pdf`);
});
},

PDF會以正確的大小和頁面長度下載,但所有頁面均為空白。 我應該對緩沖區進行不同的編碼嗎? 還有其他我想念的東西嗎?

將文檔上傳到DocuSign時,您可以將原始文檔字節作為multipart/form-data request一部分發送,也可以在請求正文中的document節點中將文檔作為base64編碼的文件發送。

但是,一旦信封完成,DocuSign平台就會將文檔轉換為PDF(如果還不是PDF)並提供該原始文件。 因此,您無需對文檔進行base64解碼,因此我將嘗試刪除代碼的這一部分。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM