in reply to Re^3: Dancer::send_file only for POST?
in thread Solved: Dancer::send_file doesn't work with POST? ( Angular JS hijacks the response)

Hi Corion, apologies, it is 0500 and I was posting on phone. Back at PC now.

This is a Dancer app running nicely with starman.

This code results in the browser downloading a CSV file:

get '/test/csv' => sub { my $csv = "foo, bar, baz"; send_file( \$csv, content_type => 'text/csv', filename => 'qux.csv +' ); };
While this code results in nothing: no error in the log, no content returned to browser:
post '/test/csv' => sub { my $csv = "foo, bar, baz"; send_file( \$csv, content_type => 'text/csv', filename => 'qux.csv +' ); };

I am using POST since the request is made from JS which knows about the user's environment.

The way forward always starts with a minimal test.

Replies are listed 'Best First'.
Re^5: Dancer::send_file only for POST?
by Corion (Patriarch) on Nov 11, 2015 at 14:34 UTC

    Thanks for your example. I had originally misunderstood your post in that it seemed that POST works but GET fails. But from reading your code, it seems to be the other way around.

    I found Dancer diagnostics to be horrible and do not trust its log anymore. Have you made sure that warnings do not get treated as fatal by Dancer? Maybe trace that the POST handler actually gets invoked by doing print-debugging.

    If all else fails, redirect to a GET handler from your POST handler:

    post '/test/csv' => sub { return redirect '/test/csv'; };

      Thanks Corion. The confusion in the OP was entirely my fault.

      I implemented a redirect but the result is the same: the print statement, which I placed immediately before the redirect, is output but then nothing in browser or log.

      The way forward always starts with a minimal test.