1
\$\begingroup\$

I often get lines like this in my Apache error log:

File does not exist: /path/to/www/data:image/gif;base64,R0lGODlhBgAGAIAOAP/yH5BAEACAEALAAAAAAGGAYAAAIJhB0Xi5vOoFwFADs=

Obviously, this is due to somebody using an outdated browser (or a robot) which doesn't handle inline images (Data URI/base64 encoded).

I am thinking it must be easy to redirect requests starting with "data:image/gif;base64," to a short perl CGI script which returns the requested value as a binary image, with the correct content header (both GIFs and PNGs are used), and without having to read any image files.

I am thinking something along the lines of the following CGI (after a rewrite places the request URL in the query string):

#!/usr/bin/perl
use strict;
use warnings;
use MIME::Base64 ();
$ENV{QUERY_STRING} =~ m{^data:(\w+/\w+);base64,(.+)$} or die "bad input";
print "Content-Type: 1ドル\n\n";
print MIME::Base64::decode (2ドル);

Would that work and would there be any downsides to this approach (apart from accommodating people with last-century browsers)?

Jamal
35.2k13 gold badges134 silver badges238 bronze badges
asked Aug 18, 2012 at 11:08
\$\endgroup\$
0

1 Answer 1

2
\$\begingroup\$

The only real problem I see is that if the browser is really "last century" it probably won't support a long enough query string to contain the full image. So your returned image might be incomplete. Another thing is that this would waste a lot of bandwidth.

I see two options

  • To suppress those error messages you could just handle those URLs like you and make a header redirect (to use the browser cache!) to an error/empty image.

  • Use conditional comments to load inline images on IE < 8 with a normal img:src attribute. Since your culprit is most likely an Internet Explorer (people who install alternate browsers usually keep them up to date)

I would use the first actually, as it does not involve changing code.

To test whether your solution works, start Internet Explorer (9), open the Web Development tools, and dial it back to IE 6 or 7 (best try both)

answered Aug 27, 2012 at 22:14
\$\endgroup\$
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.