Mojoli...derFile(3pm)
π Mojolicious::Plugin::RenderFile β aka Mojoli...derFile(3pm) π
okay bestie, this is a page from the User Contributed Perl Documentation, and it's about Mojolicious::Plugin::RenderFile β a whole plugin whose entire personality is handing files to browsers. Let's get into it β¨
πΈ NAME πΈ
Mojolicious::Plugin::RenderFile β the "render_file" helper for Mojolicious. that's it, that's the name, and it ate. π
β¨ SYNOPSIS β¨
like, here's the whole vibe in code, no notes:
# 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
);
see how easy?? iconic behavior honestly π«Ά
π¦ DESCRIPTION π¦
Mojolicious::Plugin::RenderFile is a Mojolicious plugin that adds the "render_file" helper. and here's the part that lowkey matters the most: it does not read the file into memory β it just streams it to the client. memory stays unbothered, file goes straight through. main character energy fr fr. β¨
π HELPERS π
"render_file"
$self->render_file(filepath => '/tmp/files/file.pdf', 'filename' => 'report.pdf' );
with this helper you can give your people files to download, easy peasy. by default the "Content-Type" header is "application/x-download" and the "content_disposition" option value is "attachment". so yeah, a browser is gonna ask where you wanna save the file. π
if you want the "Content-Type" header to be something else, just pass the "format" option. boom.
Supported Options: (aka the menu, bestie)
"filepath"β the path on the filesystem to the file. you must always pass either the"filepath"option or the"data"option. no exceptions, it's giving required. π"data"β binary content which will be transferred to browser. again: you must always pass either"filepath"or"data". pick one, bestie."filename"(optional) β the browser will use this name when saving the file. cute, right?"format"(optional) β the"Content-Type"header is based on the MIME type mapping of the"format"option value. and you can extend or change those mappings super easily with"types" in Mojolicious. by default though, the"Content-Type"header is"application/x-download"."content_disposition"(optional) β tells the browser how to present the file, and there are exactly two moods:"attachment"(default) β is for downloading"inline"β is for showing the file inline
"cleanup"(optional) β indicates if the file should be deleted when rendering is complete. so like, self-cleaning, we love a tidy queen. π§
also!! this plugin respects HTTP Range headers. periodt. π₯
π AUTHOR π
Viktor Turskyi <koorchik@cpan.org>
π CONTRIBUTORS π
Nils Diewald (Akron) Danil Greben (SDSWanderer)
π BUGS π
found a bug or want a feature? please report any bugs or feature requests to Github: https://github.com/koorchik/Mojolicious-Plugin-RenderFile
(be nice about it, they're doing their best π«Ά)
π SEE ALSO π
Mojolicious, Mojolicious::Guides, http://www.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.
okay that's the whole page, you're so welcome π
this was perl v5.36.0, dated 2022-08-28, and it's the Mojoli...derFile(3pm) page β go stream some files, bestie, slay πΈβ¨π¦
π¦ where this page comes from
- ubuntu noble: libmojolicious-plugin-renderfile-perl 0.12-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libmojolicious-plugin-renderfile-perl 0.12-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libmojolicious-plugin-renderfile-perl 0.12-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms