Perl
Chilkat2 Perl
Base64 Encode a File
_LANGUAGE_ to Base64 encode the contents of a file.Chilkat Perl Downloads
use strict;
use warnings;
use Chilkat2;
# Get the contents of a file into a base64 encoded string:
my $fac = Chilkat2::FileAccess->new;
my $strBase64 = $fac->ReadBinaryToEncoded('c:/data/something.pdf', 'base64');
if (!$fac->LastMethodSuccess) {
print $fac->LastErrorText, "\n";
exit;
}
# Now write the string to a file:
my $success = $fac->WriteEntireTextFile('c:/data/something_pdf_base64.txt', $strBase64, 'us-ascii', 0);
if (!$success) {
print $fac->LastErrorText, "\n";
exit;
}
print "Success!\n";