|
List Info
Thread: Dynamically generating file for download
|
|
| Dynamically generating file for download |

|
2007-07-25 20:27:10 |
|
Hi,
I have an Embperl 2.0 based website with lots of epl files in the root directory to build the page templates, etc.
I have a need to dynamically generate a data file for users to download based on form input.
I am not sure how I can generate a response to form submission that does not include the page template html automatically added by the epl files in the root directory. I also need to return the HTTP response with an appropriate MIME content type, etc.
Now, I could generate a file somewhere on disk and then send a 302 redirect to it, or ust use a CGI to generate the file based on an embperl form but I'd rather do it all dynamically with one page in Embperl.
Does anyone have any suggestions how I can approach this?
Thanks.
|
| Re: Dynamically generating file for
download |
  Germany |
2007-07-26 05:43:48 |
Lelton schrieb:
> Does anyone have any suggestions how I can approach
this?
>
> Thanks.
>
%http_headers_out is what you are looking for:
$http_headers_out{'Content-Type'} = '' the type of your
data";
my $binary_data = collect_the_data(%params);
print OUT $binary_data;
exit;
--
mit freundlichem Gruß,
Frank Wesemann
Fotofinder GmbH USt-IdNr. DE812854514
Software Entwicklung Web: http://www.fotofinder.net/
Potsdamer Str. 96 Tel: +49 30 25 79 28 90
10785 Berlin Fax: +49 30 25 79 28 999
Sitz: Berlin
Amtsgericht Berlin Charlottenburg (HRB 73099)
Geschäftsführer: Ali Paczensky
------------------------------------------------------------
---------
To unsubscribe, e-mail: embperl-unsubscribe perl.apache.org
For additional commands, e-mail: embperl-help perl.apache.org
|
|
| Re: Dynamically generating file for
download |
  United States |
2007-07-26 14:05:42 |
I think he's also wanting to either use EmbPerl instead of
EmbPerlObject
for that page, or put it in a directory with a null base.epo
(or
equivalent).
I haven't attempted to bypass that in EmbPerlObject yet, so
what Frank
said may actually be sufficient. However, it sounds a lot
like what
I've used to bypass EmbPerl additions, and I think you'd
need to also
bypass the EmbPerlObject stuff - unless Gerald has been
working his
magic again.
Ed
On Thu, 26 Jul 2007, Frank Wesemann wrote:
> Lelton schrieb:
> > Does anyone have any suggestions how I can
approach this?
> >
> > Thanks.
> >
> %http_headers_out is what you are looking for:
>
> $http_headers_out{'Content-Type'} = '' the type of
your data";
> my $binary_data = collect_the_data(%params);
> print OUT $binary_data;
> exit;
>
> --
> mit freundlichem Gruß,
>
> Frank Wesemann
> Fotofinder GmbH USt-IdNr. DE812854514
> Software Entwicklung Web: http://www.fotofinder.net/
> Potsdamer Str. 96 Tel: +49 30 25 79 28 90
> 10785 Berlin Fax: +49 30 25 79 28 999
>
> Sitz: Berlin
> Amtsgericht Berlin Charlottenburg (HRB 73099)
> Geschäftsführer: Ali Paczensky
>
>
>
>
>
------------------------------------------------------------
---------
> To unsubscribe, e-mail: embperl-unsubscribe perl.apache.org
> For additional commands, e-mail: embperl-help perl.apache.org
>
>
------------------------------------------------------------
---------
To unsubscribe, e-mail: embperl-unsubscribe perl.apache.org
For additional commands, e-mail: embperl-help perl.apache.org
|
|
| Re: Dynamically generating file for
download |

|
2007-07-26 18:28:03 |
On 7/26/07, Frank Wesemann <f.wesemann fotofinder.net> wrote:
>
> %http_headers_out is what you are looking for:
>
> $http_headers_out{'Content-Type'} = '' the type of
your data";
> my $binary_data = collect_the_data(%params);
> print OUT $binary_data;
> exit;
Thanks for the reply but that does not solve the problem.
The
content-type is the easy part! With that code in a [- -] I
still get
the inherited HTML templates which gets stuck in with the
contents of
$binary_data in the rendered output.
As Ed mentioned, I need some way of preventing Embperl from
processing
any of the inherited templates in base.epl within a
particular branch
within the program logic.
Thanks.
------------------------------------------------------------
---------
To unsubscribe, e-mail: embperl-unsubscribe perl.apache.org
For additional commands, e-mail: embperl-help perl.apache.org
|
|
| Re: Dynamically generating file for
download |
  United States |
2007-07-27 11:56:30 |
On Fri, 27 Jul 2007, Lelton wrote:
> On 7/26/07, Frank Wesemann <f.wesemann fotofinder.net> wrote:
>>
>> %http_headers_out is what you are looking for:
>>
>> $http_headers_out{'Content-Type'} = '' the type of
your data";
>> my $binary_data = collect_the_data(%params);
>> print OUT $binary_data;
>> exit;
>
> Thanks for the reply but that does not solve the
problem. The
> content-type is the easy part! With that code in a [-
-] I still get
> the inherited HTML templates which gets stuck in with
the contents of
> $binary_data in the rendered output.
>
> As Ed mentioned, I need some way of preventing Embperl
from processing
> any of the inherited templates in base.epl within a
particular branch
> within the program logic.
The way you word this seems to me ambiguous. Are you
needing assistance
in how to do the two options I mentioned?
To have EmbPerl process it instead of EmbPerlObject, you'd
basically
define a different file extension in apache, and configure
it to use
EmbPerl for that extension.
To have an empty base.epo, you'd simply copy either
/dev/null or nul
(depending on your OS) to base.epo into a subdirectory
specifically for
pages without templates.
Ed
------------------------------------------------------------
---------
To unsubscribe, e-mail: embperl-unsubscribe perl.apache.org
For additional commands, e-mail: embperl-help perl.apache.org
|
|
| Re: Dynamically generating file for
download |

|
2007-07-27 21:52:14 |
On 7/28/07, Ed Grimm <edgrimm dsblade00.wat.us.ray.com> wrote:
> The way you word this seems to me ambiguous. Are you
needing assistance
> in how to do the two options I mentioned?
I'm not sure how I can articulate it clearer. I have a
working embperl
based website with lots of included epl files that build
page
templates, etc. Every subsequent html file contains
text/code which
sits inside each page template which is automatically
generated and
then served.
What I want to do for ONE particular page is have it
generate a file
that can be downloaded. Now, the user visits the particular
html page
(which is rendered with all the templates), fills in some
details,
clicks submit (which is a FORM action back to the same page)
and then
the HTTP response is the file to download.
Now, this can be easily achieved by some [$if defined..]
statements to
check if the form variables have been filled in and then
response back
the the file to download.
The problem is that the file download would include the HTML
templates
that are provided as part of base.epl, etc thus making the
file
download littered with HTML garbage. Now, I could circumvent
that by
placing it all in a new directory and have a null base.epl
however
that does not solve my problem because I want the templates
rendered
in the first place when the form variables need to be
specified!
So if that's not clear enough, here's some pseudocode:
$ cat generate.html
[$if !defined(form variables)$]
<!-- stuff in base.epl with Execute, etc will be
automaticall included here -->
Text:
<FORM ACTION="generate.html">
....
</FORM>
Text
<!-- and here -->
[$else$]
call_some_function_that_prevents_any_templates_from_being_pr
ocessed();
[-
# perl to generate the file.
$header{'content_type'} = 'text/text';
print OUT ...
-]
[$endif]
Is that at all possible with Embperl?
Thanks.
------------------------------------------------------------
---------
To unsubscribe, e-mail: embperl-unsubscribe perl.apache.org
For additional commands, e-mail: embperl-help perl.apache.org
|
|
| Re: Dynamically generating file for
download |
  Germany |
2007-07-31 04:25:46 |
Hello Lelton,
I usually do it the same way as Ed suggested. Use a
different file
extension for Embperl pages and pure perl pages. Here's an
exerpt from
my apache.conf:
Options +ExecCGI
AddHandler cgi-script .pl
<FilesMatch ".*.html$">
SetHandler perl-script
PerlHandler HTML::EmbperlObject
</FilesMatch>
So .html files are handles by Embperl and .pl files are just
plainly
called. If performance would be important for this website I
could have
used the mod_perl registry for the .pl files.
The form (in your Embperl code) then looks like:
<form action="download.pl">
<input name="whatever"/>
</form>
And my stub for download.pl:
#!/usr/bin/env perl
use CGI;
my $cgi=new CGI;
my $whatever=$cgi->param('whatever');
my
$c=magic_function_to_generate_content_into_scalar($whatever)
;
print "Content-Type: image/pngnn";
print $c;
exit 0;
--
---> Dirk Jagdmann ^ doj / cubic
----> http://cubic.org/~doj
-----> http://llg.cubic.org
------------------------------------------------------------
---------
To unsubscribe, e-mail: embperl-unsubscribe perl.apache.org
For additional commands, e-mail: embperl-help perl.apache.org
|
|
| Re: Dynamically generating file for
download |
  Mexico |
2007-07-31 11:39:38 |
Lelton dijo [Fri, Jul 27, 2007 at 09:28:03AM +1000]:
> Thanks for the reply but that does not solve the
problem. The
> content-type is the easy part! With that code in a [-
-] I still get
> the inherited HTML templates which gets stuck in with
the contents of
> $binary_data in the rendered output.
>
> As Ed mentioned, I need some way of preventing Embperl
from processing
> any of the inherited templates in base.epl within a
particular branch
> within the program logic.
Hi,
You might want to take a look at a little system I wrote,
implementing
a simple SMB-to-web read-only gateway using Embperl. It
includes the
answer to this point you are raising, although I don't know
it's done
in the cleanest way - but it works perfectly
http://www.gwolf.org/soft/smbgate/SmbGate-1.0.tar.gz
There are still some references to my workplace sprinkled
through the
code - If you want to use it, look for any occurrences of
the 'iiec'
string
Greetings,
--
Gunnar Wolf - gwolf gwolf.org - (+52-55)5623-0154 / 1451-2244
PGP key 1024D/8BB527AF 2001-10-23
Fingerprint: 0C79 D2D1 2C4E 9CE4 5973 F800 D80E F35A 8BB5
27AF
------------------------------------------------------------
---------
To unsubscribe, e-mail: embperl-unsubscribe perl.apache.org
For additional commands, e-mail: embperl-help perl.apache.org
|
|
| Re: Dynamically generating file for
download |
  United States |
2007-07-31 14:03:32 |
On Sat, 28 Jul 2007, Lelton wrote:
> On 7/28/07, Ed Grimm <edgrimm dsblade00.wat.us.ray.com> wrote:
>
> > The way you word this seems to me ambiguous. Are
you needing assistance
> > in how to do the two options I mentioned?
>
> I'm not sure how I can articulate it clearer. I have a
working embperl
> based website with lots of included epl files that
build page
> templates, etc. Every subsequent html file contains
text/code which
> sits inside each page template which is automatically
generated and
> then served.
>
> What I want to do for ONE particular page is have it
generate a file
> that can be downloaded. Now, the user visits the
particular html page
> (which is rendered with all the templates), fills in
some details,
> clicks submit (which is a FORM action back to the same
page) and then
> the HTTP response is the file to download.
You may have gathered this from the other people who have
responded to
this, but there is no easy way to do this in EmbPerlObject.
A single
file will always either load the template or not, depending
on its
applicable <Location>, <Directory>, and
<FilesMatch> settings, and the
template file associated with its directory location.
You *could* make the base.epo file be smart enough that it
recognized
when a particular page is loaded *and* has form data, to not
show any
template. I think that would be unwise, but it could be
done.
What could be a bit simpler and more clever, while not
straying too far
from your 'pure' state, would be to have a link to the file
with the
same name except for the extension - something like
% ls index.*
-rw-r--r-- 1 eg other 5503 Jul 31 2007
index.html
lrw-r--r-- 1 eg other 9 Jul 31 2007
index.txt -> index.html
%
Now, have the action link to the other extension name.
That having been said - I used to do web pages that had the
same script
generate the form and process the form. I had enough
problems with
doing that in various template environments that I decided,
for testing
purposes, I'd stop fighting it temporarily and have a
different file to
process the action from the one to generate the form - and
it was so
much easier to work with it that way that the temporary
became
permanent; I would now resist any effort to make me go back
to that.
It's a coding style that has been given in examples by many
books and
HOWTO documents, but it does not seem to me to be actually
good for
everyday use. Since I stopped using that design, I had the
opportunity
to talk to one book author who had used it - who apologized
for having
lead me astray; he admitted that it wasn't normally good
coding design,
he had only used it in the book because it let him fit the
text in page
boundaries better. I cannot say that the other authors were
using it
for that reason, but the experience reminded me that I
should always
think before adopting someone's practices, and try to
determine if there
is any reason why their practice might not be appropriate
for me.
Ed
------------------------------------------------------------
---------
To unsubscribe, e-mail: embperl-unsubscribe perl.apache.org
For additional commands, e-mail: embperl-help perl.apache.org
|
|
[1-9]
|
|