perl:用于返回“图像数据uri”的正确“内容类型”格式 [英] perl: correct `content type` formatting for returning `image data uri`

查看:118
本文介绍了perl:用于返回“图像数据uri”的正确“内容类型”格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 angularjs 中有一个模板,期望通过<$调用的服务器调用返回的 image data uri 模板 img 元素的c $ c> src 属性:

I have a template in angularjs expecting the image data uri returned by a server call invoked through the src attribute of the img element of the template:

<img width="200px" height="200px" src="http://localhost:3000/returnimage" />

在服务器端,用 Perl 编写与 Dancer 我有:

On the server side, written in Perl with Dancer I have:

any ['get', 'post'] => '/returnimage' => sub {
    content_type 'image/jpeg;base64;';
    'data:image/jpeg;base64,/9j/4gIcSUNDX1B....N5f2hqE//Z';
};

模板渲染的结果是损坏的图像标签:


但调用已执行:

The result on template render is a broken image tag: But the call is executed:

网络响应和预览不可用。但是,如果我直接从浏览器调用 http:// localhost:3000 / returnimage ,它们确实包含完整的 image数据uri 作为'data:image / jpeg; base64,/ 9j / 4gIcSUNDX1B .... N5f2hqE // Z'。尽管会出现黑色图像,并且在检查时会显示黑色图像:

The network response and preview are unavailable. But if I call http://localhost:3000/returnimage directly from the browser they do contain the complete image data uri as 'data:image/jpeg;base64,/9j/4gIcSUNDX1B....N5f2hqE//Z'. ALthough a black image shows up and when inspected:

关于问题/修复的任何想法吗?

Any ideas on problem/fix ?

推荐答案

Perl子例程:

my $photo = '/9j/4gIcSUNDX....oqOU1MzEFUa8x2MJf5JUjFV3llWW3UVscTLNhd93KFWQUrqHn/ABEc2CfmIASx0nMWLiN5f2hqE//Z';
my $decoded= MIME::Base64::decode_base64($photo);
content_type 'image/jpeg';
$decoded;

这篇关于perl:用于返回“图像数据uri”的正确“内容类型”格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆