#vba #api #ms-access #signnow
#vba #API #ms-access #signnow
Вопрос:
У меня есть учетная запись в изолированной среде для тестирования API в signnow. я тестирую API шаг за шагом, чтобы убедиться, что я могу выполнить интеграцию с помощью Access VBA.
Я смог получить токен доступа, используя этот код:
Private Sub Command5_Click()
sUrl = "https://api-eval.signnow.com/oauth2/token"
sUsername = "rami_jebara@hotmail.com"
sPassword = "XXXXXXXX"
AsToken = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
sgrant_type = "password"
sscope = "*"
sbody = "username=" amp; sUsername amp; "amp;password=" amp; sPassword amp; "amp;grant_type=" amp; sgrant_type amp; "amp;scope=" amp; sscope
' Make the request
With CreateObject("MSXML2.XMLHTTP.6.0")
.Open "Post", sUrl, False
.SetRequestHeader "Authorization", "basic " amp; AsToken
.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
.Send sbody
Debug.Print .responseText
Debug.Print .GetAllResponseHeaders
TempVars.Add "ACToken", .responseText
Me.Requery
Text0.Requery
End With
End Sub
Я успешно предоставляю токен доступа
Но теперь я застрял при загрузке PDF-файла из Ms Access в Signnow Ниже кода, который я использую
Option Compare Database
Private Function GetFileSize(fileFullPath As String) As Long
Dim lngFSize As Long, lngDSize As Long
Dim oFO As Object, OFS As Object
lngFSize = 0
Set OFS = CreateObject("Scripting.FileSystemObject")
If OFS.FileExists(fileFullPath) Then
Set oFO = OFS.getFile(fileFullPath)
GetFileSize = 31812
Else
GetFileSize = 0
End If
Set oFO = Nothing
Set OFS = Nothing
End Function
Private Function ReadBinary(strFilePath As String)
Dim ado As Object, bytFile
Set ado = CreateObject("ADODB.Stream")
ado.Type = 1
ado.Open
ado.LoadFromFile strFilePath
bytFile = ado.Read
ado.Close
ReadBinary = bytFile
Set ado = Nothing
End Function
Private Function toArray(str)
Dim ado As Object
Set ado = CreateObject("ADODB.Stream")
ado.Type = 2
ado.Charset = "_autodetect"
ado.Open
ado.WriteText (str)
ado.Position = 0
ado.Type = 1
toArray = ado.Read()
Set ado = Nothing
End Function
Function POST_multipart_form_data(filePath As String)
Dim oFields As Object, ado As Object
Dim sBoundary As String, sPayLoad As String
Dim fileType As String, fileExtn As String, fileName As String
Dim sName As Variant
fileName = Right(filePath, Len(filePath) - InStrRev(filePath, ""))
fileExtn = Right(filePath, Len(fileName) - InStrRev(fileName, "."))
Select Case fileExtn
Case "pdf"
fileType = "application/pdf"
Case "jpg"
fileType = "image/jpeg"
Case "txt"
fileType = "text/plain"
End Select
sBoundary = String(27, "-")
sPayLoad = ""
sPayLoad = sPayLoad amp; "--" amp; sBoundary amp; vbCrLf
sPayLoad = sPayLoad amp; "Content-Disposition: form-data; name=""file""; " amp; "filename=""" amp; fileName amp; """" amp; vbCrLf
sPayLoad = sPayLoad amp; "Content-Type: " amp; fileType amp; vbCrLf amp; vbCrLf amp; vbCrLf amp; vbCrLf amp; vbCrLf
sPayLoad = sPayLoad amp; "--" amp; sBoundary amp; "--"
Set ado = CreateObject("ADODB.Stream")
ado.Type = 1
ado.Open
ado.Write toArray(sPayLoad)
ado.Write ReadBinary(filePath)
ado.Position = 0
With CreateObject("MSXML2.ServerXMLHTTP")
.Open "POST", "https://api-eval.signnow.com/document", False
.SetRequestHeader "Authorization", "bearer " amp; "e3c9d47d08199cf8a4baa6529c8dc3349c0f76380c3a0fecf0842ddd600711aa"
.SetRequestHeader "Content-Type", "multipart/form-data; boundary=" amp; sBoundary
.Send (ado.Read())
MsgBox .responseText
End With
End Function
он возвращает эту ошибку
{
"errors": [
{
"code": 66048,
"message": "Unable to upload pdf document, pdf document headers are malformed"
}
]
}
Теперь, когда я работаю над этой ошибкой в течение двух недель, мне нужна помощь.
Заранее спасибо