Empty Fax using VB6

  • 1
  • Problem
  • Updated 1 month ago
Hi ! 
i'm trying to send PDF file using MSXML2.xmlhttp but the client receive empty pdf File as an attachement without any errors. i'm using Visual basic 6.0 to send requests. i sent the same file with RingCentral Web APP and it works. i think the binary conversion is not working proprely here is my code

Function CreateFaxMessage(strPath, _
                          strStatus, _<br>                          Receiver, _<br>                          Optional coverPageText = "", _<br>                          Optional strResponse = "", _<br>                          Optional faxResolution As String = "High") As Boolean
        Dim strFile, strExt, strContentType, strBoundary, bytData, bytPayLoad
        On Error Resume Next
104     With CreateObject("Scripting.FileSystemObject")
106         If .FileExists(strPath) Then<br>108             strFile = .GetFileName(strPath)<br>110             strExt = .GetExtensionName(strPath)<br>            Else<br>112             strStatus = "File not found"<br>114             CreateFaxMessage = False
                Exit Function
            End If
        End With
116     With CreateObject("Scripting.Dictionary")<br>146         .Add "pdf", "application/pdf"<br>148         strContentType = .Item(LCase(strExt))<br>        End With
150     If strContentType = "" Then<br>152         strStatus = "Invalid file type"<br>154         CreateFaxMessage = False<br>            Exit Function<br>        End If
174     strBoundary = String(2, "-") & Replace(Mid(CreateObject("Scriptlet.TypeLib").Guid, 2, 36), "-", "")<br>    Dim nFile           As Integer<br>    Dim baBuffer()      As Byte<br>    Dim sPostData       As String
     '--- read file<br>    nFile = FreeFile<br>    Open strPath For Binary Access Read As nFile<br>    If LOF(nFile) > 0 Then<br>        ReDim baBuffer(0 To LOF(nFile) - 1) As Byte<br>        Get nFile, , baBuffer<br>        sPostData = StrConv(baBuffer, vbFromUnicode)<br>    End If<br>    Close nFile<br>    '--- prepare body<br>        sPostData = strBoundary & vbCrLf & _<br>        "Content-Disposition: form-data; name=""attachment""; filename=""" & strFile & """" & vbCrLf & _<br>        "Content-Transfer-Encoding: binary" & vbCrLf & _<br>        "Content-Type: " & strContentType & vbCrLf & vbCrLf & _<br>        sPostData & vbCrLf<br>        sPostData = sPostData & strBoundary & "--"
        Dim params As String
220     params = strBoundary & vbCrLf<br>222     params = params & "Content-Disposition: form-data; name=""faxResolution""" & vbCrLf & vbCrLf<br>224     params = params & faxResolution & vbCrLf
232     params = params & strBoundary & vbCrLf<br>        params = params & "Content-Disposition: form-data; name=""to""" & vbCrLf & vbCrLf<br>        params = params & Receiver & vbCrLf             
        Dim XMLHTTP As Object
218     Set XMLHTTP = CreateObject("MSXML2.ServerXMLHTTP")
240     With XMLHTTP<br>242         .setTimeouts 0, 60000, 300000, 300000<br>244         .Open "POST", FaxURL, False<br>246         '.setRequestHeader "Accept", "application/json; boundary=" & strBoundary<br>248         .setRequestHeader "Content-Type", "multipart/form-data; boundary=" & Mid(strBoundary, 3)<br>250         .setRequestHeader "Authorization", "Bearer " & RingCentral.AccessToken<br>252         .send params & sPostData
260         If Ok(.status) Then<br>262             strResponse = .responseText<br>264             CreateFaxMessage = True
            Else<br>266             MsgBox .statusText & " (" & .status & ")"<br>            End If
        End With
        Exit Function<br>&nbsp;<br>End Function
Photo of Rachid Abbouchi

Rachid Abbouchi

  • 90 Points 75 badge 2x thumb

Posted 4 months ago

  • 1
Photo of Tyler Long

Tyler Long, Official Rep

  • 8,704 Points 5k badge 2x thumb
Could you please reformat the code? 

We don't have any SDK for VB6. But if you use VB.net, you can use the C# SDK: https://github.com/ringcentral/ringcentral-csharp-client