Converting binary file to Base64 string

后端 未结 6 1555
小鲜肉
小鲜肉 2021-01-13 06:41

I need to convert uploaded binary files to base64 string format on the fly. I\'m using ASP, Vbscript. Using Midori\'s component for base64 conversion. For small size files (

6条回答
  •  太阳男子
    2021-01-13 07:18

    This is what worked for me

    Function Base64DataURI(url)
    
        'Create an Http object, use any of the four objects
        Dim Http
        Set Http = CreateObject("WinHttp.WinHttpRequest.5.1")
    
        'Send request To URL
        Http.Open "GET", url, False
        Http.Send
        'Get response data As a string and encode as base64
        Base64DataURI = Encrypt(Http.ResponseText)
    End Function
    

    In my case the URL is a script that generates a barcode on the fly and needed to encode to include that in emails.

    Encrypt is a pretty standard function we use to encode as Base64, but the main concept we needed was to get the file via URL not file system.

提交回复
热议问题