Programming Reference Manual
 
Syntax
 
Decode64_File(Data, FilePath)
 
Description
Decode a base64-encoded string and write the resulting binary data directly to a file. Returns 1 on success, 0 on failure. This function writes the decoded binary content directly to disk without intermediate string conversion, making it significantly faster than using Decode64 followed by a file write operation. This is particularly beneficial for large binary payloads such as uploaded images, PDFs and other documents. Internally, the function uses the Chilkat BinData component for high-performance native decoding. If the base64 data is invalid or the file cannot be written (e.g. the target directory does not exist or the file is locked), 0 is returned.
 
Parameter
Description
Data
The base64-encoded string to decode.
FilePath
Full destination path for the output file, e.g. "O:\Documenten\Upload\foto.jpg". The directory must already exist.
See Also
Example
Sub Main
Dim sBase64 As String
Dim iResult As Integer
 
' Read base64 data from a database field or POST variable
sBase64 = SQL.RunQueryGet1Field("SELECT ImageData FROM dbo.Uploads WITH (READUNCOMMITTED) WHERE ID = 1")
 
iResult = Decode64_File(sBase64, "O:\Documenten\Upload\ontvangen_foto.jpg")
If iResult = 1 Then
Debug.Print "File saved successfully."
Else
Debug.Print "<span style='color: #004080; font-weight: bold;'>Error</span>: decode or write failed."
End If
End Sub