Mojolicious::Plugin::RenderFile(3pm) | User Contributed Perl Documentation | Mojolicious::Plugin::RenderFile(3pm) |
Mojolicious::Plugin::RenderFile - "render_file" helper for Mojolicious
# Mojolicious $self->plugin('RenderFile'); # Mojolicious::Lite plugin 'RenderFile'; # In controller $self->render_file('filepath' => '/tmp/files/file.pdf'); # file name will be "file.pdf" # Provide any file name $self->render_file('filepath' => '/tmp/files/file.pdf', 'filename' => 'report.pdf'); # Render data from memory as file $self->render_file('data' => 'some data here', 'filename' => 'report.pdf'); # Open file in browser(do not show save dialog) $self->render_file( 'filepath' => '/tmp/files/file.pdf', 'format' => 'pdf', # will change Content-Type "application/x-download" to "application/pdf" 'content_disposition' => 'inline', # will change Content-Disposition from "attachment" to "inline" 'cleanup' => 1, # delete file after completed );
Mojolicious::Plugin::RenderFile is a Mojolicious plugin that adds "render_file" helper. It does not read file in memory and just streaming it to a client.
$self->render_file(filepath => '/tmp/files/file.pdf', 'filename' => 'report.pdf' );
With this helper you can easily provide files for download. By default "Content-Type" header is "application/x-download" and "content_disposition" option value is "attachment". Therefore, a browser will ask where to save file. You can provide "format" option to change "Content-Type" header.
Supported Options:
By default "Content-Type" header is "application/x-download"
"attachment" (default) - is for dowloading
"inline" - is for showing file inline
This plugin respects HTTP Range headers.
Viktor Turskyi <koorchik@cpan.org>
Nils Diewald (Akron) Danil Greben (SDSWanderer)
Please report any bugs or feature requests to Github <https://github.com/koorchik/Mojolicious-Plugin-RenderFile>
Mojolicious, Mojolicious::Guides, <http://mojolicio.us>.
Copyright 2011 Viktor Turskyi
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
2017-09-30 | perl v5.26.0 |