Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: ModPerl: ModPerl

Download then display page

 

 

ModPerl modperl RSS feed   Index | Next | Previous | View Threaded


cfaust at doyougot

Apr 30, 2013, 9:32 AM

Post #1 of 7 (282 views)
Permalink
Download then display page

Hi,



I'm trying to have a form submission package up the results in a xls file
and then start the download for the user as well as present a page where
they can click on the file if the download has not already automatically
started.



I can do each separately but not both together, I have something like this:



... Make up our xls file download and put it in $output



$r->content_type('application/xls');

$r->err_headers_out->add('Content-Disposition' => 'attachment; filename="' .
$download_name . '"');

$r->print($output);

$content->param('set some html template vars....');

$r->content_type('text/html');

print $content->output;



When I due the above, then I get prompted for the download but that is it, I
never get the page. Even if I reverse the order and try to do the page
first:



$r->content_type('text/html');

print $content->output;

$r->content_type('application/xls');

$r->err_headers_out->add('Content-Disposition' => 'attachment; filename="' .
$download_name . '"');

$r->print($output);

$content->param('set some html template vars....');



That still doesn't work. Probably not a mod_perl specific question but I'm
hoping someone can shed some light



TIA!

-Chris


jschueler at eloquency

Apr 30, 2013, 10:52 AM

Post #2 of 7 (266 views)
Permalink
Re: Download then display page [In reply to]

I believe the following will work (never tried it though):

The request should return a 'text/html' type document that displays the
instructions. But the response should be a redirect to a URL that returns
the spreadsheet instead of a 200 OK. I believe that the body of the
original response will be displayed until the redirect succeeds.

In the old days, we performed this trick by using meta tag equivalents of
the response headers. And I expect browsers will respond to actual HTTP
headers the same way. I say "the old days" because for last 18 years,
I've relied on javascript. But there may be reasons for not wanting a
different type solution.

-Jim




On Tue, 30 Apr 2013, Chris Faust wrote:

>
> Hi,
>
>  
>
> I'm trying to have a form submission package up the results in a xls file
> and then start the download for the user as well as present a page where
> they can click on the file if the download has not already automatically
> started.
>
>  
>
> I can do each separately but not both together, I have something like this:
>
>  
>
> ... Make up our xls file download and put it in $output
>
>  
>
> $r->content_type('application/xls');
>
> $r->err_headers_out->add('Content-Disposition' => 'attachment; filename="' .
> $download_name . '"');
>
> $r->print($output);
>
> $content->param('set some html template vars....');
>
> $r->content_type('text/html');
>
> print $content->output;
>
>  
>
> When I due the above, then I get prompted for the download but that is it, I
> never get the page. Even if I reverse the order and try to do the page
> first:
>
>  
>
> $r->content_type('text/html');
>
> print $content->output;
>
> $r->content_type('application/xls');
>
> $r->err_headers_out->add('Content-Disposition' => 'attachment; filename="' .
> $download_name . '"');
>
> $r->print($output);
>
> $content->param('set some html template vars....');
>
>  
>
> That still doesn't work. Probably not a mod_perl specific question but I'm
> hoping someone can shed some light
>
>  
>
> TIA!
>
> -Chris
>
>  
>
>  
>
>
>


cfaust at doyougot

Apr 30, 2013, 11:15 AM

Post #3 of 7 (262 views)
Permalink
RE: Download then display page [In reply to]

>>But the response should be a redirect to a URL that returns the
spreadsheet instead of a 200 OK. I believe that the body of the original
response will be displayed until the redirect succeeds.

I'm not sure what I follow you, something like this?

$r->content_type('text/html');
print $content->output;
$r->headers_out->set(Location => $redirect);
return Apache2::Const::REDIRECT;

And the $redirect URL would then do the sending of the file itself?

Thanks!


-----Original Message-----
From: Jim Schueler [mailto:jschueler [at] eloquency]
Sent: Tuesday, April 30, 2013 1:53 PM
To: Chris Faust
Cc: modperl [at] perl
Subject: Re: Download then display page

I believe the following will work (never tried it though):

The request should return a 'text/html' type document that displays the
instructions. But the response should be a redirect to a URL that returns
the spreadsheet instead of a 200 OK. I believe that the body of the
original response will be displayed until the redirect succeeds.

In the old days, we performed this trick by using meta tag equivalents of
the response headers. And I expect browsers will respond to actual HTTP
headers the same way. I say "the old days" because for last 18 years, I've
relied on javascript. But there may be reasons for not wanting a different
type solution.

-Jim




On Tue, 30 Apr 2013, Chris Faust wrote:

>
> Hi,
>
>  
>
> I'm trying to have a form submission package up the results in a xls
> file and then start the download for the user as well as present a
> page where they can click on the file if the download has not already
> automatically started.
>
>  
>
> I can do each separately but not both together, I have something like
this:
>
>  
>
> ... Make up our xls file download and put it in $output
>
>  
>
> $r->content_type('application/xls');
>
> $r->err_headers_out->add('Content-Disposition' => 'attachment; filename="'
.
> $download_name . '"');
>
> $r->print($output);
>
> $content->param('set some html template vars....');
>
> $r->content_type('text/html');
>
> print $content->output;
>
>  
>
> When I due the above, then I get prompted for the download but that is
> it, I never get the page. Even if I reverse the order and try to do
> the page
> first:
>
>  
>
> $r->content_type('text/html');
>
> print $content->output;
>
> $r->content_type('application/xls');
>
> $r->err_headers_out->add('Content-Disposition' => 'attachment; filename="'
.
> $download_name . '"');
>
> $r->print($output);
>
> $content->param('set some html template vars....');
>
>  
>
> That still doesn't work. Probably not a mod_perl specific question but
> I'm hoping someone can shed some light
>
>  
>
> TIA!
>
> -Chris
>
>  
>
>  
>
>
>


jschueler at eloquency

Apr 30, 2013, 11:27 AM

Post #4 of 7 (266 views)
Permalink
RE: Download then display page [In reply to]

Yes, that's what I have in mind. I only occassionally write headers.
But I envision something similar to what you've got below:

$redirect = ... ; ## URL to the spreadsheet

$r->content_type('text/html') ;
$r->headers_out->set( Location => $redirect ) ;
$r->send_http_header ;

$r->print( $content->output ) ;
return Apache2::Const::REDIRECT ;

Originally, I wondered about using a "multipart/mixed" response type.
I've never heard that any browser supports such a thing. Although that
seems like a more elegant solution.

-Jim

On Tue, 30 Apr 2013, Chris Faust wrote:

>>> But the response should be a redirect to a URL that returns the
> spreadsheet instead of a 200 OK. I believe that the body of the original
> response will be displayed until the redirect succeeds.
>
> I'm not sure what I follow you, something like this?
>
> $r->content_type('text/html');
> print $content->output;
> $r->headers_out->set(Location => $redirect);
> return Apache2::Const::REDIRECT;
>
> And the $redirect URL would then do the sending of the file itself?
>
> Thanks!
>
>
> -----Original Message-----
> From: Jim Schueler [mailto:jschueler [at] eloquency]
> Sent: Tuesday, April 30, 2013 1:53 PM
> To: Chris Faust
> Cc: modperl [at] perl
> Subject: Re: Download then display page
>
> I believe the following will work (never tried it though):
>
> The request should return a 'text/html' type document that displays the
> instructions. But the response should be a redirect to a URL that returns
> the spreadsheet instead of a 200 OK. I believe that the body of the
> original response will be displayed until the redirect succeeds.
>
> In the old days, we performed this trick by using meta tag equivalents of
> the response headers. And I expect browsers will respond to actual HTTP
> headers the same way. I say "the old days" because for last 18 years, I've
> relied on javascript. But there may be reasons for not wanting a different
> type solution.
>
> -Jim
>
>
>
>
> On Tue, 30 Apr 2013, Chris Faust wrote:
>
>>
>> Hi,
>>
>>  
>>
>> I'm trying to have a form submission package up the results in a xls
>> file and then start the download for the user as well as present a
>> page where they can click on the file if the download has not already
>> automatically started.
>>
>>  
>>
>> I can do each separately but not both together, I have something like
> this:
>>
>>  
>>
>> ... Make up our xls file download and put it in $output
>>
>>  
>>
>> $r->content_type('application/xls');
>>
>> $r->err_headers_out->add('Content-Disposition' => 'attachment; filename="'
> .
>> $download_name . '"');
>>
>> $r->print($output);
>>
>> $content->param('set some html template vars....');
>>
>> $r->content_type('text/html');
>>
>> print $content->output;
>>
>>  
>>
>> When I due the above, then I get prompted for the download but that is
>> it, I never get the page. Even if I reverse the order and try to do
>> the page
>> first:
>>
>>  
>>
>> $r->content_type('text/html');
>>
>> print $content->output;
>>
>> $r->content_type('application/xls');
>>
>> $r->err_headers_out->add('Content-Disposition' => 'attachment; filename="'
> .
>> $download_name . '"');
>>
>> $r->print($output);
>>
>> $content->param('set some html template vars....');
>>
>>  
>>
>> That still doesn't work. Probably not a mod_perl specific question but
>> I'm hoping someone can shed some light
>>
>>  
>>
>> TIA!
>>
>> -Chris
>>
>>  
>>
>>  
>>
>>
>>
>
>
>


adam.prime at utoronto

Apr 30, 2013, 11:54 AM

Post #5 of 7 (266 views)
Permalink
Re: Download then display page [In reply to]

I think people still generally rely on meta redirects or javascript to
accomplish this type of behaviour, though I'm curious to know if what
you describe here actually works across browsers.

Adam


On 13-04-30 02:27 PM, Jim Schueler wrote:
> Yes, that's what I have in mind. I only occassionally write headers.
> But I envision something similar to what you've got below:
>
> $redirect = ... ; ## URL to the spreadsheet
>
> $r->content_type('text/html') ;
> $r->headers_out->set( Location => $redirect ) ;
> $r->send_http_header ;
>
> $r->print( $content->output ) ;
> return Apache2::Const::REDIRECT ;
>
> Originally, I wondered about using a "multipart/mixed" response type.
> I've never heard that any browser supports such a thing. Although that
> seems like a more elegant solution.
>
> -Jim
>
> On Tue, 30 Apr 2013, Chris Faust wrote:
>
>>>> But the response should be a redirect to a URL that returns the
>> spreadsheet instead of a 200 OK. I believe that the body of the original
>> response will be displayed until the redirect succeeds.
>>
>> I'm not sure what I follow you, something like this?
>>
>> $r->content_type('text/html');
>> print $content->output;
>> $r->headers_out->set(Location => $redirect);
>> return Apache2::Const::REDIRECT;
>>
>> And the $redirect URL would then do the sending of the file itself?
>>
>> Thanks!
>>
>>
>> -----Original Message-----
>> From: Jim Schueler [mailto:jschueler [at] eloquency]
>> Sent: Tuesday, April 30, 2013 1:53 PM
>> To: Chris Faust
>> Cc: modperl [at] perl
>> Subject: Re: Download then display page
>>
>> I believe the following will work (never tried it though):
>>
>> The request should return a 'text/html' type document that displays the
>> instructions. But the response should be a redirect to a URL that
>> returns
>> the spreadsheet instead of a 200 OK. I believe that the body of the
>> original response will be displayed until the redirect succeeds.
>>
>> In the old days, we performed this trick by using meta tag equivalents of
>> the response headers. And I expect browsers will respond to actual HTTP
>> headers the same way. I say "the old days" because for last 18 years,
>> I've
>> relied on javascript. But there may be reasons for not wanting a
>> different
>> type solution.
>>
>> -Jim
>>
>>
>>
>>
>> On Tue, 30 Apr 2013, Chris Faust wrote:
>>
>>>
>>> Hi,
>>>
>>>
>>>
>>> I'm trying to have a form submission package up the results in a xls
>>> file and then start the download for the user as well as present a
>>> page where they can click on the file if the download has not already
>>> automatically started.
>>>
>>>
>>>
>>> I can do each separately but not both together, I have something like
>> this:
>>>
>>>
>>>
>>> ... Make up our xls file download and put it in $output
>>>
>>>
>>>
>>> $r->content_type('application/xls');
>>>
>>> $r->err_headers_out->add('Content-Disposition' => 'attachment;
>>> filename="'
>> .
>>> $download_name . '"');
>>>
>>> $r->print($output);
>>>
>>> $content->param('set some html template vars....');
>>>
>>> $r->content_type('text/html');
>>>
>>> print $content->output;
>>>
>>>
>>>
>>> When I due the above, then I get prompted for the download but that is
>>> it, I never get the page. Even if I reverse the order and try to do
>>> the page
>>> first:
>>>
>>>
>>>
>>> $r->content_type('text/html');
>>>
>>> print $content->output;
>>>
>>> $r->content_type('application/xls');
>>>
>>> $r->err_headers_out->add('Content-Disposition' => 'attachment;
>>> filename="'
>> .
>>> $download_name . '"');
>>>
>>> $r->print($output);
>>>
>>> $content->param('set some html template vars....');
>>>
>>>
>>>
>>> That still doesn't work. Probably not a mod_perl specific question but
>>> I'm hoping someone can shed some light
>>>
>>>
>>>
>>> TIA!
>>>
>>> -Chris
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>
>>
>>


cfaust at doyougot

Apr 30, 2013, 11:56 AM

Post #6 of 7 (262 views)
Permalink
RE: Download then display page [In reply to]

Thanks Jim, I'm going to give that a try and see if I can get it to work.

-Chris

-----Original Message-----
From: Jim Schueler [mailto:jschueler [at] eloquency]
Sent: Tuesday, April 30, 2013 2:28 PM
To: Chris Faust
Cc: modperl [at] perl
Subject: RE: Download then display page

Yes, that's what I have in mind. I only occassionally write headers.
But I envision something similar to what you've got below:

$redirect = ... ; ## URL to the spreadsheet

$r->content_type('text/html') ;
$r->headers_out->set( Location => $redirect ) ;
$r->send_http_header ;

$r->print( $content->output ) ;
return Apache2::Const::REDIRECT ;

Originally, I wondered about using a "multipart/mixed" response type.
I've never heard that any browser supports such a thing. Although that
seems like a more elegant solution.

-Jim

On Tue, 30 Apr 2013, Chris Faust wrote:

>>> But the response should be a redirect to a URL that returns the
> spreadsheet instead of a 200 OK. I believe that the body of the
> original response will be displayed until the redirect succeeds.
>
> I'm not sure what I follow you, something like this?
>
> $r->content_type('text/html');
> print $content->output;
> $r->headers_out->set(Location => $redirect); return
> Apache2::Const::REDIRECT;
>
> And the $redirect URL would then do the sending of the file itself?
>
> Thanks!
>
>
> -----Original Message-----
> From: Jim Schueler [mailto:jschueler [at] eloquency]
> Sent: Tuesday, April 30, 2013 1:53 PM
> To: Chris Faust
> Cc: modperl [at] perl
> Subject: Re: Download then display page
>
> I believe the following will work (never tried it though):
>
> The request should return a 'text/html' type document that displays
> the instructions. But the response should be a redirect to a URL that
> returns the spreadsheet instead of a 200 OK. I believe that the body
> of the original response will be displayed until the redirect succeeds.
>
> In the old days, we performed this trick by using meta tag equivalents
> of the response headers. And I expect browsers will respond to actual
> HTTP headers the same way. I say "the old days" because for last 18
> years, I've relied on javascript. But there may be reasons for not
> wanting a different type solution.
>
> -Jim
>
>
>
>
> On Tue, 30 Apr 2013, Chris Faust wrote:
>
>>
>> Hi,
>>
>>  
>>
>> I'm trying to have a form submission package up the results in a xls
>> file and then start the download for the user as well as present a
>> page where they can click on the file if the download has not already
>> automatically started.
>>
>>  
>>
>> I can do each separately but not both together, I have something like
> this:
>>
>>  
>>
>> ... Make up our xls file download and put it in $output
>>
>>  
>>
>> $r->content_type('application/xls');
>>
>> $r->err_headers_out->add('Content-Disposition' => 'attachment;
filename="'
> .
>> $download_name . '"');
>>
>> $r->print($output);
>>
>> $content->param('set some html template vars....');
>>
>> $r->content_type('text/html');
>>
>> print $content->output;
>>
>>  
>>
>> When I due the above, then I get prompted for the download but that
>> is it, I never get the page. Even if I reverse the order and try to
>> do the page
>> first:
>>
>>  
>>
>> $r->content_type('text/html');
>>
>> print $content->output;
>>
>> $r->content_type('application/xls');
>>
>> $r->err_headers_out->add('Content-Disposition' => 'attachment;
filename="'
> .
>> $download_name . '"');
>>
>> $r->print($output);
>>
>> $content->param('set some html template vars....');
>>
>>  
>>
>> That still doesn't work. Probably not a mod_perl specific question
>> but I'm hoping someone can shed some light
>>
>>  
>>
>> TIA!
>>
>> -Chris
>>
>>  
>>
>>  
>>
>>
>>
>
>
>


jschueler at eloquency

Apr 30, 2013, 11:59 AM

Post #7 of 7 (269 views)
Permalink
RE: Download then display page [In reply to]

To clarify, I meant to say, "I only occassionally write handlers". :)

-Jim

On Tue, 30 Apr 2013, Chris Faust wrote:

> Thanks Jim, I'm going to give that a try and see if I can get it to work.
>
> -Chris
>
> -----Original Message-----
> From: Jim Schueler [mailto:jschueler [at] eloquency]
> Sent: Tuesday, April 30, 2013 2:28 PM
> To: Chris Faust
> Cc: modperl [at] perl
> Subject: RE: Download then display page
>
> Yes, that's what I have in mind. I only occassionally write headers.
> But I envision something similar to what you've got below:
>
> $redirect = ... ; ## URL to the spreadsheet
>
> $r->content_type('text/html') ;
> $r->headers_out->set( Location => $redirect ) ;
> $r->send_http_header ;
>
> $r->print( $content->output ) ;
> return Apache2::Const::REDIRECT ;
>
> Originally, I wondered about using a "multipart/mixed" response type.
> I've never heard that any browser supports such a thing. Although that
> seems like a more elegant solution.
>
> -Jim
>
> On Tue, 30 Apr 2013, Chris Faust wrote:
>
>>>> But the response should be a redirect to a URL that returns the
>> spreadsheet instead of a 200 OK. I believe that the body of the
>> original response will be displayed until the redirect succeeds.
>>
>> I'm not sure what I follow you, something like this?
>>
>> $r->content_type('text/html');
>> print $content->output;
>> $r->headers_out->set(Location => $redirect); return
>> Apache2::Const::REDIRECT;
>>
>> And the $redirect URL would then do the sending of the file itself?
>>
>> Thanks!
>>
>>
>> -----Original Message-----
>> From: Jim Schueler [mailto:jschueler [at] eloquency]
>> Sent: Tuesday, April 30, 2013 1:53 PM
>> To: Chris Faust
>> Cc: modperl [at] perl
>> Subject: Re: Download then display page
>>
>> I believe the following will work (never tried it though):
>>
>> The request should return a 'text/html' type document that displays
>> the instructions. But the response should be a redirect to a URL that
>> returns the spreadsheet instead of a 200 OK. I believe that the body
>> of the original response will be displayed until the redirect succeeds.
>>
>> In the old days, we performed this trick by using meta tag equivalents
>> of the response headers. And I expect browsers will respond to actual
>> HTTP headers the same way. I say "the old days" because for last 18
>> years, I've relied on javascript. But there may be reasons for not
>> wanting a different type solution.
>>
>> -Jim
>>
>>
>>
>>
>> On Tue, 30 Apr 2013, Chris Faust wrote:
>>
>>>
>>> Hi,
>>>
>>>  
>>>
>>> I'm trying to have a form submission package up the results in a xls
>>> file and then start the download for the user as well as present a
>>> page where they can click on the file if the download has not already
>>> automatically started.
>>>
>>>  
>>>
>>> I can do each separately but not both together, I have something like
>> this:
>>>
>>>  
>>>
>>> ... Make up our xls file download and put it in $output
>>>
>>>  
>>>
>>> $r->content_type('application/xls');
>>>
>>> $r->err_headers_out->add('Content-Disposition' => 'attachment;
> filename="'
>> .
>>> $download_name . '"');
>>>
>>> $r->print($output);
>>>
>>> $content->param('set some html template vars....');
>>>
>>> $r->content_type('text/html');
>>>
>>> print $content->output;
>>>
>>>  
>>>
>>> When I due the above, then I get prompted for the download but that
>>> is it, I never get the page. Even if I reverse the order and try to
>>> do the page
>>> first:
>>>
>>>  
>>>
>>> $r->content_type('text/html');
>>>
>>> print $content->output;
>>>
>>> $r->content_type('application/xls');
>>>
>>> $r->err_headers_out->add('Content-Disposition' => 'attachment;
> filename="'
>> .
>>> $download_name . '"');
>>>
>>> $r->print($output);
>>>
>>> $content->param('set some html template vars....');
>>>
>>>  
>>>
>>> That still doesn't work. Probably not a mod_perl specific question
>>> but I'm hoping someone can shed some light
>>>
>>>  
>>>
>>> TIA!
>>>
>>> -Chris
>>>
>>>  
>>>
>>>  
>>>
>>>
>>>
>>
>>
>>
>
>
>

ModPerl modperl RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.