On Mon, Apr 17, 2017 at 2:29 PM, iaw4 <[email protected]> wrote:
> dear M experts---how do I give a specific name to a binary data format
> that the browser will download, such as
>
> $c->render( data => $zipfileinmemory, format => 'zip', name =>
> 'backedup-at-'.time() );
>
> this does not work. name is ignored.
>
Here's how I've done it:
package WebApp::Controller::Form;
use Mojo::Base 'Mojolicious::Controller';
sub download {
my $self = shift;
my $form_name = $self->param('form_name') or return
$self->reply->not_found;
my $type = $self->param('type');
my $download = $self->forms->$form_name->download($type);
return $self->reply->not_found unless $download;
$self->res->headers->content_disposition("attachment;
filename=\"$form_name-$type.csv\"");
$self->reply->table(csv => $download);
}
> also, is it possible to initiate a browser download and then redirect to
> another web page upon completion?
>
I believe I've seen this done using frames. One frame downloads the
attachment while the other frame has a redirect, like a meta refresh html
element.
This seems like a better method
<http://stackoverflow.com/questions/822707/php-generate-file-for-download-then-redirect>,
it's in PHP, but the concept applies equally well.
--
You received this message because you are subscribed to the Google Groups
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.