question on downloading CGI
question on downloading CGI
am 05.09.2008 18:09:59 von Practical Perl
Hello,
I want to generate a data file which should be downloaded by clients.
Rather than generate this file and put it in a web dir and tell
clients to download it, is there any way to generate the content
dynamicly and put it to cients? I mean I don't want to generate the
temporary file. Thanks.
Jen.
Re: question on downloading CGI
am 05.09.2008 18:46:52 von Sean Davis
On Fri, Sep 5, 2008 at 12:09 PM, wrote:
> Hello,
>
> I want to generate a data file which should be downloaded by clients.
> Rather than generate this file and put it in a web dir and tell
> clients to download it, is there any way to generate the content
> dynamicly and put it to cients? I mean I don't want to generate the
> temporary file. Thanks.
Hi, Jen. This list is for mod_perl users. It sounds like you are new
to web programming, but I could be wrong. I would suggest with a
google search for "perl cgi tutorial" and go from there. There is
also a beginners-cgi mailing list (not this) and perlmonks.org is a
great site for general perl knowledge.
Sean
Re: question on downloading CGI
am 05.09.2008 19:10:25 von torsten.foertsch
On Fri 05 Sep 2008, practicalperl@gmail.com wrote:
> I want to generate a data file which should be downloaded by clients.
> Rather than generate this file and put it in a web dir and tell
> clients to download it, is there any way to generate the content
> dynamicly and put it to cients? I mean I don't want to generate the
> temporary file.
Plenty.
For example in your httpd.conf
SetHandler modperl
PerlResponseHandler "sub { \
use Apache2::RequestRec (); \
use Apache2::RequestIO (); \
use Apache2::Connection (); \
$_[0]->content_type('application/octet-stream'); \
until($_[0]->connection->aborted) { \
$_[0]->print(rand); \
} \
return 0; \
}"
Now restart your server and then
curl -v http://server/download
And you'll get never ending randomness.
You can also write a little shell script and use it via mod_cgi:
>>>>>>>>>>>>>>>>>> the shell script
#!/bin/bash
echo Content-Type: application/octet-stream
echo
cat /dev/urandom
<<<<<<<<<<<<<<<<<< end of shell script
Now fetch the Apache docs and configure your server to execute the
script as CGI program.
Remember it is not necessarily faster to send dynamic content this way.
Sometimes it is faster to write a temporary file sometime before the
response phase and let the default handler send it. If you decide to
send the content on the fly try to figure out the content length and
set the Content-Length header. This can also improve your performance.
Torsten
--
Need professional mod_perl support?
Just hire me: torsten.foertsch@gmx.net
Re: question on downloading CGI
am 05.09.2008 21:51:12 von Adam Prime
Quoting practicalperl@gmail.com:
> Hello,
>
> I want to generate a data file which should be downloaded by clients.
> Rather than generate this file and put it in a web dir and tell
> clients to download it, is there any way to generate the content
> dynamicly and put it to cients? I mean I don't want to generate the
> temporary file. Thanks.
This reads to me like you just want to cause the browser to prompt the
user to save the file to disk instead of render the content you are
generating in which case you should read about the Content-Disposition
header:
http://www.ietf.org/rfc/rfc1806.txt
The quick summary of which is to add a header to your response that
looks like this:
Content-Disposition: attachment; filename=filename.extention
Adam
Re: question on downloading CGI
am 08.09.2008 10:45:32 von Practical Perl
Thank you all so much. I have resolved the problems.
On Sat, Sep 6, 2008 at 3:51 AM, wrote:
> Quoting practicalperl@gmail.com:
>
>> Hello,
>>
>> I want to generate a data file which should be downloaded by clients.
>> Rather than generate this file and put it in a web dir and tell
>> clients to download it, is there any way to generate the content
>> dynamicly and put it to cients? I mean I don't want to generate the
>> temporary file. Thanks.
>
> This reads to me like you just want to cause the browser to prompt the user
> to save the file to disk instead of render the content you are generating in
> which case you should read about the Content-Disposition header:
>
> http://www.ietf.org/rfc/rfc1806.txt
>
> The quick summary of which is to add a header to your response that looks
> like this:
>
> Content-Disposition: attachment; filename=filename.extention
>
> Adam
>
>
>
>
>
>