in reply to Solved: Dancer::send_file doesn't work with POST? ( Angular JS hijacks the response)

Even the Dancer documentation shows as an example a GET request/handler for send_file, so I would assume that it works. But the documentation also lists some prerequisites like the file living below the public directory etc.

Maybe you can show us a small example of how send_file fails for you?

Replies are listed 'Best First'.
Re^2: Dancer::send_file only for POST?
by 1nickt (Canon) on Nov 11, 2015 at 13:44 UTC
    Sorry, too early! Updated my question which is about in-memory "files" only.
    The way forward always starts with a minimal test.

      I'm sorry to be so snarky, but as I've already asked you to provide more detail, I'll quote your signature here:

      The way forward always starts with a minimal test.

      Please, do provide us with a minimal example that we can use to reproduce your case. Also tell us what PSGI webserver you're using. Different webservers have different features and maybe the webserver your're using tries to be smart about sending files by delegating this task to the operating system by name.

      Some of the tests seem to allow send_file( \$data, ... ), so maybe you're not filling $data properly in the GET case? A short example should help us help you better here.

        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.