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
On 05/11/2010 21:30, P Kishor wrote:
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?
set show_errors => 1; might help -- Alexis Sukrieh
A small pitfall in send_file is that the files should be in the apps public folder. I think this is your problem. 2010/11/5 P Kishor <punk.kish@gmail.com>:
On the other hand, if the image does exist, I get a 404 (not found).
What is going on here? Any ideas?
2010/11/6 Иван Бессарабов <ivan@bessarabov.ru>:
A small pitfall in send_file is that the files should be in the apps public folder. I think this is your problem.
Sadly this is not the pitfall (I think). The images are in app/ public/ images/ foo/ a_1.gif a_2.gif a_n.gif b_1.gif b_2.gif b_n.gif bar/ a_1.gif a_2.gif a_n.gif b_1.gif b_2.gif b_n.gif If I get access them directly as in /app/images/foo/b_1.gif or /app/images/bar/b_3.gif it all works fine. However, I want to instead query for /app/<foo|bar>/<a|b>/<\d>. Then, if the image exists, just send it back, else create it and send it back. My sense is that it is not possible to send an image back as a result of an ajax query. An ajax query can only return text, json or html (all different kinds of text, really). I am assuming that send_file() sends a binary stream back that the browser has no way of handling as a result of an ajax request. Am I right or wrong?
2010/11/5 P Kishor <punk.kish@gmail.com>:
On the other hand, if the image does exist, I get a 404 (not found).
What is going on here? Any ideas?
-- Puneet Kishor http://www.punkish.org Carbon Model http://carbonmodel.org Charter Member, Open Source Geospatial Foundation http://www.osgeo.org Science Commons Fellow, http://sciencecommons.org/about/whoweare/kishor Nelson Institute, UW-Madison http://www.nelson.wisc.edu ----------------------------------------------------------------------- Assertions are politics; backing up assertions with evidence is science =======================================================================
If i understand you correctly everything is working right when you request images from browser.
My sense is that it is not possible to send an image back as a result of an ajax query. An ajax query can only return text, json or html (all different kinds of text, really). I am assuming that send_file() sends a binary stream back that the browser has no way of handling as a result of an ajax request.
Am I right or wrong?
I think that you are right. If you need and image from ajax request you can just get the url of that image and then use the use to place the image on the page or something.
participants (3)
-
Alexis Sukrieh -
P Kishor -
Иван Бессарабов