Sub UploadFile
    Try
        'This is pretty much a straight rip off from the Perl example given in the docs
        Dim mCRLF As String = $"${Chr(13)}${Chr(10)}"$
        ' PLD TEST URL
        Dim upsURL As String = "https://www.pld-certify.ups.com/hapld/tos/kdwhapltos"
       
        ' open and readl the pld0200 file
        Dim pldFileContent As String = File.ReadString(File.DirAssets, "sample2.txt")
       
         ' create message part 1
        Dim msg_part1 As String ' = "AppVersion=1.0&AcceptUPSLicenseAgreement=YES&ResponseType=application/x-ups-pld&VersionNumber=V4R1&UserId=PLDDSTEST&Password=PLDDSTEST"
        'Java code sample mentions URL encoding these items
        msg_part1 = UrlEncodeMap(CreateMap("AppVersion":"1.0","AcceptUPSLicenseAgreement":"YES","ResponseType":"application/x-ups-pld","VersionNumber":"V4R1","UserId":"PLDDSTEST","Password":"PLDDSTEST"))
        Dim msg_part1_header1 As String = "Content-type: application/x-www-form-urlencoded"
        Dim msg_part1_header2 As String = $"Content-length: ${msg_part1.Length}"$
        msg_part1 = $"${msg_part1_header1}${mCRLF}${msg_part1_header2}${mCRLF}${mCRLF}${msg_part1}"$
       
        ' create message part 2
        Dim msg_part2 As String = pldFileContent
        Dim msg_part2_header1 As String = "Content-type: application/x-ups-binary"
        Dim msg_part2_header2 As String = $"Content-length: ${msg_part2.Length}"$
        msg_part2 = $"${msg_part2_header1}${mCRLF}${msg_part2_header2}${mCRLF}${mCRLF}${msg_part2}"$
       
        ' create the complete request message
        Dim PLDmsg As String = $"--BOUNDARY${mCRLF}${msg_part1}${mCRLF}${mCRLF}--BOUNDARY${mCRLF}${msg_part2}${mCRLF}${mCRLF}--BOUNDARY--"$
        Log(PLDmsg.Length)
        Dim job As HttpJob
        job.Initialize("", Me)
        'job.PostString("https://posttestserver.dev/p/0v2ofpzj1gqfm08m/post", PLDmsg)
        job.PostString(upsURL, PLDmsg)
        job.GetRequest.SetContentType("multipart/mixed; boundary=BOUNDARY")
        Log("Uploading file...")
        Wait For (job) JobDone(job As HttpJob)
        If job.Success Then
            Dim input As InputStream = job.GetInputStream
            Log($"Input bytes: ${input.BytesAvailable}"$)
            Log("Success: " & job.GetString)
        Else
            Log("Failed: " & job.ErrorMessage)
        End If
    Catch
        Log("Error: " & LastException.Message)
    End Try
    job.Release
End Sub
'https://www.b4x.com/android/forum/threads/b4x-urlencodemap.118626/
' UrlEncodeMap(input As Map) As String
' Converts a Map's keys/values to a URL encoded parameter string
' Following library is used
' B4J - jStringUtils
' B4A - StringUtils
' B4i - iStringUtils
Sub UrlEncodeMap(input As Map) As String
    Dim sb As StringBuilder
    Dim su As StringUtils
    sb.Initialize
    Dim first As Boolean = True
    For Each key In input.Keys
        If Not(first) Then
            sb.Append("&")
        Else
            first = False
        End If
        sb.Append($"${su.EncodeUrl(key, "UTF8")}=${su.EncodeUrl(input.Get(key), "UTF8")}"$)
    Next
    Return sb.ToString
End Sub