简体   繁体   中英

DocuSign API Javascript SDK - getDocument returns string

I am trying to call the api endpoint getDocument via Node, and am expecting a Buffer to be returned, however, it is returning a string. Even when I pass in different values for the encoding optional parameter, the data returned is always the same.

When I tested the same endpoint in C#, a MemoryStream is returned which is expected.

My code is as follows:

const document = await envelopesApi.getDocument(accountId, envelopeId, '1')

Where 1 is the documentId (page 1).

The contents of document looks like %PDF-1.5\n%ûüýþ\n%Writing objects... and so on

I am then trying to save this to a file:

fs.writeFileSync('test.pdf', Buffer.from(documentContent))

With no success. How do I get the api response and save it to a file for viewing?

Yes, this is correct, you will have to use the correct mime type for PDF (in this case) in order to show this file in the browser.

You can find a node.JS code example that shows you how to do this.

But the most important part in your case would be this line:

mimetype = "application/pdf";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM