我正在更新访问包含客户数据的MSSQL 2008数据库的CGI应用程序。数据库由第三方应用程序管理,因此我无法更改数据结构。
其中一个表格('来宾')包含一个列' mug_shot'类型'图像'该列包含每个guest虚拟机的JPEG图像。从此列检索数据时,它始终显示为文本格式。例如,当我执行以下查询时:
my $mugshotQuery = "SELECT TOP 1 mug_shot FROM guests where guest_no = ?";
my $mugshotStatementHandle = $dbh->prepare($mugshotQuery);
$mugshotStatementHandle->execute($guest_number);
并获取数据:
my $mugshotHash = $mugshotStatementHandle->fetchrow_hashref();
$mugshotHash->{mug_shot}
包含JPEG二进制数据的十六进制表示。这是一个缩短的例子:
ffd8ffe000104a46494600010101004c004c0000ffe1004245786966000049492a000800000002001a01050001000000260000001b0105000100000030000000000000007d3b8c0440420f000000ed168e0440420f000000ffdb0043000302020302020303030304030304050805050404050a070706080c0a0c0c0b0a0b0b0d0e12100d0e110e0b0b1016101113141515150c0f171816141812141514ffdb00430103040405040509050509140d0b0d1414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414ffc00011080156010003012200021101031101ffc4001f0000010501010101010100000000000000000102030405060708090a0bffc400b5100002010303020403050504040000017d01020300041105122131410613516107227114328191a1082342b1c11552d1f02433627282090a161718191a25262728292a3435363738393a434445464748494a535455565758595a636465666768696a737475767778797a838485868788898a92939495969798999aa2a3a4a5a6a7a8a9aab2b3b4b5b6b7b8b9bac2c3c4c5c6c7c8c9cad2d3d4d5d6d7d8d9dae1e2e3e4e5e6e7e8e9eaf1f2f3f4f5f6f7f8f9faffc4001f0100030101010101010101010000000000000102030405060708090a0bffc400b51100020102040403040705040400010277000102031104052131061241510761711322328108144291a1b1c109233352f0156272d10a162434e125f11718191a262728292a35363738393a434445464748494a535455565758595a636465666768696a737475767778797a82838485868788898a92939495969798999aa2a3a4a5a6a7a8a9aab2b3b4b5b6b7b8b9bac2c3c4c5c6c7c8c9cad2d3d4d5d6d7d8d9dae2e3e4e5e6e7e8e9eaf2f3f4f5f6f7f8f9faffda000c03010002110311003f00bd3dc482790798ff0078ff0011f5a68b9931feb1ff0033493f133f7f98ff003a6923d39aed48f997e63fed1267fd63
因此,我尝试显示图像失败:
print STDOUT "Content-type: image/jpeg\n";
print STDOUT "Content-length: \n\n";
binmode STDOUT;
print STDOUT $mugshotHash->{mug_shot};
浏览器报告图像无效。为什么数据以文本/十六进制而不是二进制数据的形式返回,我该怎么做才能获取二进制数据?
答案 0 :(得分:0)
有一个标志以二进制格式返回图像数据:
$dbh->{syb_binary_images} = 1;
设置此标志后,图像以正确的格式返回。为了更好地衡量,我还使用以下内容确保图像不会被截断:
$dbh->{LongTruncOK} = 0;
$dbh->do("set textsize 1000000");