无法使用DocuSign REST API上传WORD文档

时间:2016-04-12 09:28:05

标签: docusignapi

我正在尝试使用其余API将 WORD文档(* .doc)上传到docusign,并使用以下代码。但抛出异常 - UNABLE_TO_LOAD_DOCUMENT,文档损坏。如果我使用同一文档使用我的开发帐户直接从docusign网站上传,它会正确上传而不会出现任何错误。任何人都可以帮我找出下面的代码有什么问题。 (以下代码适用于.PDF格式文件

byte[] fileBytes = File.ReadAllBytes(pathOfTheWordDocFile);
EnvelopeDefinition envDef = new EnvelopeDefinition();
envDef.EmailSubject = "[DocuSign C# SDK] - Please sign this doc";

// Add a document to the envelope
Document doc = new Document();
doc.DocumentBase64 = System.Convert.ToBase64String(fileBytes);
doc.Name = Path.GetFileName(strPath);
doc.DocumentId = "1";

envDef.Documents = new List<DocuSignModel.Document>();
envDef.Documents.Add(doc);

1 个答案:

答案 0 :(得分:6)

默认情况下,文档content-type设置为application/pdf。要使用不同的mime类型,您只需使用

设置文件扩展名
doc.FileExtension = "docx";

尝试在代码中添加该行,它应该可以正常工作,如下所示:

byte[] fileBytes = File.ReadAllBytes(pathOfTheWordDocFile);
EnvelopeDefinition envDef = new EnvelopeDefinition();
envDef.EmailSubject = "[DocuSign C# SDK] - Please sign this doc";

// Add a document to the envelope
Document doc = new Document();
doc.DocumentBase64 = System.Convert.ToBase64String(fileBytes);
doc.Name = Path.GetFileName(strPath);
doc.DocumentId = "1";
doc.FileExtension = "docx";

envDef.Documents = new List<DocuSignModel.Document>();
envDef.Documents.Add(doc);