handlename's blog

コード片など

base64エンコードされた画像をデコードしてファイルに保存する

MIME::Base64 を使用。
perl v5.12.1

use MIME::Base64;

my $image_base64 = '<base64エンコードした画像'>;

# base64形式からデコード
my $image_bin = decode_base64($image_base64);

# ファイルを開く
open $fh, '+>', '/path/to/file' or die "Cannot open : $!";

# ファイルをバイナリモードに
binmode $fh;

# 書き込み
print $fh $image_bin;

# ファイルを閉じる
close $fh;