(Classic ASP) Get Contents of File as Base64
Demonstrates how to read the contents of a file and convert to a base64 string.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
' For versions of Chilkat < 10.0.0, use CreateObject("Chilkat_9_5_0.BinData")
set bd = Server.CreateObject("Chilkat.BinData")
success = bd.LoadFile("qa_data/jpg/starfish.jpg")
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( "Failed to load file.") & "</pre>"
Response.End
End If
Response.Write "<pre>" & Server.HTMLEncode( bd.GetEncoded("base64")) & "</pre>"
' If you want mult-line base64:
Response.Write "<pre>" & Server.HTMLEncode( "--") & "</pre>"
Response.Write "<pre>" & Server.HTMLEncode( bd.GetEncoded("base64_mime")) & "</pre>"
' If you want hex..
Response.Write "<pre>" & Server.HTMLEncode( "--") & "</pre>"
Response.Write "<pre>" & Server.HTMLEncode( bd.GetEncoded("hex")) & "</pre>"
' etc.
%>
</body>
</html>
|