send_file Content-Disposition
Hi All, I was having terrible trouble using send_file and the Content-Disposition header. I found that I needed to set the Content-Disposition header manually in the reponse object returned from send_file. get '/myfile' => sub { my $response = send_file('/some/file.jpg'); $response->header('Content-Disposition', "attachment; filename=some_other_file.jpg"); return $response; } Although this works and I have no problems doing it, it seems counter intuative. I would rather do: get '/myfile' => sub { header "Content-Disposition" => "attachment; filename=some_other_file.jpg" ; send_file('/some/file.jpg'); } In the highly likely event I am doing something wrong can someone let me know ? Cheers Matt.
On Mon, Feb 7, 2011 at 2:27 AM, Matthew Vickers <mvickers@quispiam.com>wrote:
Hi All,
Hey Matthew! :)
I was having terrible trouble using send_file and the Content-Disposition header. I found that I needed to set the Content-Disposition header manually in the reponse object returned from send_file.
I think send_file() should be a one-stop-shop for sending files to the user. That means that it should also set all the headers you want for you. I guess my question would be why isn't it doing so, and made you specify the header yourself.
On Mon, Feb 7, 2011 at 8:21 PM, sawyer x <xsawyerx@gmail.com> wrote:
I was having terrible trouble using send_file and the Content-Disposition
header. I found that I needed to set the Content-Disposition header manually in the reponse object returned from send_file.
I think send_file() should be a one-stop-shop for sending files to the user. That means that it should also set all the headers you want for you. I guess my question would be why isn't it doing so, and made you specify the header yourself.
Do you mean that header and send_file should play well together like the OP is hoping, or that you have to accept whatever header set send_file sets for you? Cheers, Flavio.
On Mon, Feb 7, 2011 at 11:44 PM, Flavio Poletti <polettix@gmail.com> wrote:
On Mon, Feb 7, 2011 at 8:21 PM, sawyer x <xsawyerx@gmail.com> wrote:
I was having terrible trouble using send_file and the Content-Disposition
header. I found that I needed to set the Content-Disposition header manually in the reponse object returned from send_file.
I think send_file() should be a one-stop-shop for sending files to the user. That means that it should also set all the headers you want for you. I guess my question would be why isn't it doing so, and made you specify the header yourself.
Do you mean that header and send_file should play well together like the OP is hoping,
Yup! :) Any ideas, comments?
On 07/02/11 21:52, sawyer x wrote:
On Mon, Feb 7, 2011 at 11:44 PM, Flavio Poletti <polettix@gmail.com Do you mean that header and send_file should play well together like the OP is hoping,
Yup! :)
Any ideas, comments?
Are we talking about merging the elements into the one function-call? send_file( $contents, type=>'text/foo', as_attachment=>'myfile.foo' ) -- Richard Huxton Archonet Ltd
On Tue, Feb 8, 2011 at 12:10 AM, Richard Huxton <dev@archonet.com> wrote:
On 07/02/11 21:52, sawyer x wrote:
On Mon, Feb 7, 2011 at 11:44 PM, Flavio Poletti <polettix@gmail.com Do you mean that header and send_file should play well together like the OP is hoping,
Yup! :)
Any ideas, comments?
Are we talking about merging the elements into the one function-call? send_file( $contents, type=>'text/foo', as_attachment=>'myfile.foo' )
My thoughts are more of fixing send_file itself, so Matthew (and anyone else) could just do send_file($filename).
Are we talking about merging the elements into the one function-call? send_file( $contents, type=>'text/foo', as_attachment=>'myfile.foo' )
My thoughts are more of fixing send_file itself, so Matthew (and anyone else) could just do send_file($filename).
I like this idea, mostly because it makes it easier to remember and is more logical. Send Headers, Send File. But Richard's idea with some parameters being optional for backward compatability is also good. Matt
On Tue, Feb 8, 2011 at 12:45 AM, Matthew Vickers <mvickers@quispiam.com>wrote:
Are we talking about merging the elements into the one function-call?
send_file( $contents, type=>'text/foo', as_attachment=>'myfile.foo' )
My thoughts are more of fixing send_file itself, so Matthew (and anyone else) could just do send_file($filename).
I like this idea, mostly because it makes it easier to remember and is more logical. Send Headers, Send File.
But Richard's idea with some parameters being optional for backward compatability is also good.
I'm not sure about the implementation of send_file() - I haven't checked it myself - but shouldn't it set the correct headers? What is the nature of the headers you're explicitly declaring? I should probably do some more reading instead of asking you, but it's 2am and I'm tired. :)
participants (4)
-
Flavio Poletti -
Matthew Vickers -
Richard Huxton -
sawyer x