问题
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" />
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:
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 ?
回答1:
Perl subroutine:
my $photo = '/9j/4gIcSUNDX....oqOU1MzEFUa8x2MJf5JUjFV3llWW3UVscTLNhd93KFWQUrqHn/ABEc2CfmIASx0nMWLiN5f2hqE//Z';
my $decoded= MIME::Base64::decode_base64($photo);
content_type 'image/jpeg';
$decoded;
来源:https://stackoverflow.com/questions/46565373/perl-correct-content-type-formatting-for-returning-image-data-uri