简体   繁体   English

DocuSign API Javascript SDK - getDocument 返回字符串

[英]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.我正在尝试通过 Node 调用 api 端点getDocument ,并期望返回一个 Buffer,但是,它返回一个字符串。 Even when I pass in different values for the encoding optional parameter, the data returned is always the same.即使我为encoding可选参数传入不同的值,返回的数据也始终相同。

When I tested the same endpoint in C#, a MemoryStream is returned which is expected.当我在 C# 中测试同一个端点时,返回了预期的 MemoryStream。

My code is as follows:我的代码如下:

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

Where 1 is the documentId (page 1).其中1是 documentId(第 1 页)。

The contents of document looks like %PDF-1.5\n%ûüýþ\n%Writing objects... and so on document的内容看起来像%PDF-1.5\n%ûüýþ\n%Writing objects...等等

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?如何获取 api 响应并将其保存到文件以供查看?

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.是的,这是正确的,您必须为 PDF(在本例中)使用正确的 MIME 类型才能在浏览器中显示该文件。

You can find a node.JS code example that shows you how to do this.您可以找到一个node.JS 代码示例,向您展示如何执行此操作。

But the most important part in your case would be this line:但你的情况中最重要的部分是这一行:

mimetype = "application/pdf";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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