[Dancer-users] sending an image to an ajax request

P Kishor punk.kish at gmail.com
Fri Nov 5 21:30:51 CET 2010


I have code like so -- on the client, I make an ajax request for

/image/a/b/3

on the server, I have

get '/image/:a/:b/:c' => sub {
    my $a = params->{a};
    my $b = params->{b};
    my $c = params->{c};

    my $dir = "path/to/image";
    my $img = $b . '_' . $c . '.gif';

    # $img will be created only if it doesn't already exist on disk
    unless (-e "$dir/$img") {
        app::get_image('a'  => $a, 'b' => $b, 'c' => $c);
    }

    # send the image
    send_file("$dir/$img");
};

The problem is that if the image doesn't exist, I get a 500 error
(internal server error) in the browser (in Firebug), but nothing in
the Apache error log, so I can't really decipher what is going wrong.
On the other hand, if the image does exist, I get a 404 (not found).

What is going on here? Any ideas?

-- 
Puneet Kishor


More information about the Dancer-users mailing list