Vb.net Docusign从模板下载文件,该模板使用Chilkat和rest api以文件base64字符串格式获取非法字符
我可以从传递templateid和documentid的模板获取文件,当从api重新运行时,我将获取base64string格式,当我尝试转换为byte时 我得到一个错误“附加信息:输入不是有效的Base-64字符串,因为它包含一个非Base-64字符、两个以上的填充字符或填充字符中的非法字符。” 这里是我用来从模板下载文件的代码Vb.net Docusign从模板下载文件,该模板使用Chilkat和rest api以文件base64字符串格式获取非法字符,vb.net,docusignapi,chilkat,Vb.net,Docusignapi,Chilkat,我可以从传递templateid和documentid的模板获取文件,当从api重新运行时,我将获取base64string格式,当我尝试转换为byte时 我得到一个错误“附加信息:输入不是有效的Base-64字符串,因为它包含一个非Base-64字符、两个以上的填充字符或填充字符中的非法字符。” 这里是我用来从模板下载文件的代码 Dim rest As New Chilkat.Rest Dim success As Boolean Dim bTls As Boolean
Dim rest As New Chilkat.Rest
Dim success As Boolean
Dim bTls As Boolean = True
Dim port As Integer = 443
Dim bAutoReconnect As Boolean = True
success = rest.Connect("demo.docusign.net", port, bTls, bAutoReconnect)
If (success <> True) Then
Debug.WriteLine("ConnectFailReason: " & rest.ConnectFailReason)
Debug.WriteLine(rest.LastErrorText)
Exit Sub
End If
rest.AddHeader("X-DocuSign-Authentication", "{ ""Username"": ""DocuSign@example.com"", ""Password"":""DocuSign_password"", ""IntegratorKey"":""DocuSign_Integrator_Key"" }")
Dim sbResponseBody As New Chilkat.StringBuilder
success = rest.FullRequestNoBodySb("GET", "/restapi/v2.1/accounts/xxxx/templates/xxxx-xxxx-xxxx-xxxx-xxxx/documents/x", sbResponseBody)
If (success <> True) Then
Debug.WriteLine(rest.LastErrorText)
Exit Sub
End If
Dim respStatusCode As Integer = rest.ResponseStatusCode
If (respStatusCode >= 400) Then
Debug.WriteLine("Response Status Code = " & respStatusCode)
Debug.WriteLine("Response Header:")
Debug.WriteLine(rest.ResponseHeader)
Debug.WriteLine("Response Body:")
Debug.WriteLine(sbResponseBody.GetAsString())
Exit Sub
End If
Dim jsonResponse As New Chilkat.JsonObject
jsonResponse.LoadSb(sbResponseBody)
Dim pdfBytes As Byte() = Convert.FromBase64String(sbResponseBody.ToString)
将rest调暗为新的Chilkat.rest
将成功视为布尔值
将BTL设置为布尔值=真
Dim端口为整数=443
Dim bAutoReconnect As Boolean=True
success=rest.Connect(“demo.docusign.net”、端口、bTls、bAutoReconnect)
如果(成功是真的)那么
Debug.WriteLine(“ConnectFailReason:&rest.ConnectFailReason”)
Debug.WriteLine(rest.LastErrorText)
出口接头
如果结束
AddHeader(“X-DocuSign-Authentication”,“{”“用户名”:”DocuSign@example.com“,”密码“:”文档签名\u密码“,”积分器密钥“:”文档签名\u积分器密钥“}”)
Dim sbResponseBody作为新的Chilkat.StringBuilder
success=rest.FullRequestNoBodySb(“GET”,“/restapi/v2.1/accounts/xxxx/templates/xxxx/xxxx/documents/x”,sbResponseBody)
如果(成功是真的)那么
Debug.WriteLine(rest.LastErrorText)
出口接头
如果结束
Dim respStatusCode为整数=rest.ResponseStatusCode
如果(respStatusCode>=400),则
Debug.WriteLine(“响应状态代码=“&respStatusCode”)
Debug.WriteLine(“响应头:”)
Debug.WriteLine(rest.ResponseHeader)
Debug.WriteLine(“响应主体:”)
Debug.WriteLine(sbResponseBody.GetAsString())
出口接头
如果结束
Dim jsonResponse作为新的Chilkat.JsonObject
jsonResponse.LoadSb(sbResponseBody)
Dim pdfBytes As Byte()=Convert.FromBase64String(sbResponseBody.ToString)
问候,,
Aravind我将我的代码从chilkat dll更改为Docusing dll 3.0.0,使用Docusing dll我可以从信封下载文件,在这里我通过我的代码,它将对其他开发人员有用。我使用.net framework代码从文件流下载文件
Private Function DoWnload(ByVal accessToken As String, ByVal basePath As String, ByVal accountId As String, ByVal envelopeId As String, ByVal documents As List(Of EnvelopeDocItem), ByVal docSelect As String) As String
Dim config = New Configuration(New ApiClient(basePath))
config.AddDefaultHeader("Authorization", "Bearer " & accessToken)
Dim envelopesApi As EnvelopesApi = New EnvelopesApi(config)
Dim results As System.IO.Stream = envelopesApi.GetDocument(accountId, envelopeId, docSelect)
Dim docItem As EnvelopeDocItem = documents.FirstOrDefault(Function(d) docSelect.Equals(d.DocumentId))
Dim docName As String = docItem.Name
Dim hasPDFsuffix As Boolean = docName.ToUpper().EndsWith(".PDF")
Dim pdfFile As Boolean = hasPDFsuffix
Dim docType As String = docItem.Type
If ("content".Equals(docType) OrElse "summary".Equals(docType)) AndAlso Not hasPDFsuffix Then
docName += ".pdf"
pdfFile = True
End If
If "zip".Equals(docType) Then
docName += ".zip"
End If
Dim mimetype As String
If pdfFile Then
mimetype = "application/pdf"
ElseIf "zip".Equals(docType) Then
mimetype = "application/zip"
Else
mimetype = "application/octet-stream"
End If
Dim bytesRead As Integer
Dim buffer(4096) As Byte
Using outFile As New System.IO.FileStream("C:\File.pdf", IO.FileMode.Create, IO.FileAccess.Write)
Do
bytesRead = results.Read(buffer, 0, buffer.Length)
If bytesRead > 0 Then
outFile.Write(buffer, 0, bytesRead)
End If
Loop While bytesRead > 0
End Using
Return ""
End Function
Dim envelopeDocItems As List(Of EnvelopeDocItem) = New List(Of EnvelopeDocItem) From {
New EnvelopeDocItem With {
.Name = "Combined",
.Type = "content",
.DocumentId = "combined"
},
New EnvelopeDocItem With {
.Name = "Zip archive",
.Type = "zip",
.DocumentId = "archive"
}
感谢Inbar Gazit
感谢和问候,
阿拉文德