.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Mojolicious::Plugin::RenderFile 3pm" .TH Mojolicious::Plugin::RenderFile 3pm "2022-08-28" "perl v5.34.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Mojolicious::Plugin::RenderFile \- "render_file" helper for Mojolicious .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& # Mojolicious \& $self\->plugin(\*(AqRenderFile\*(Aq); \& \& # Mojolicious::Lite \& plugin \*(AqRenderFile\*(Aq; \& \& # In controller \& $self\->render_file(\*(Aqfilepath\*(Aq => \*(Aq/tmp/files/file.pdf\*(Aq); # file name will be "file.pdf" \& \& # Provide any file name \& $self\->render_file(\*(Aqfilepath\*(Aq => \*(Aq/tmp/files/file.pdf\*(Aq, \*(Aqfilename\*(Aq => \*(Aqreport.pdf\*(Aq); \& \& # Render data from memory as file \& $self\->render_file(\*(Aqdata\*(Aq => \*(Aqsome data here\*(Aq, \*(Aqfilename\*(Aq => \*(Aqreport.pdf\*(Aq); \& \& # Open file in browser(do not show save dialog) \& $self\->render_file( \& \*(Aqfilepath\*(Aq => \*(Aq/tmp/files/file.pdf\*(Aq, \& \*(Aqformat\*(Aq => \*(Aqpdf\*(Aq, # will change Content\-Type "application/x\-download" to "application/pdf" \& \*(Aqcontent_disposition\*(Aq => \*(Aqinline\*(Aq, # will change Content\-Disposition from "attachment" to "inline" \& \*(Aqcleanup\*(Aq => 1, # delete file after completed \& ); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Mojolicious::Plugin::RenderFile is a Mojolicious plugin that adds \*(L"render_file\*(R" helper. It does not read file in memory and just streaming it to a client. .SH "HELPERS" .IX Header "HELPERS" .ie n .SS """render_file""" .el .SS "\f(CWrender_file\fP" .IX Subsection "render_file" .Vb 1 \& $self\->render_file(filepath => \*(Aq/tmp/files/file.pdf\*(Aq, \*(Aqfilename\*(Aq => \*(Aqreport.pdf\*(Aq ); .Ve .PP With this helper you can easily provide files for download. By default \*(L"Content-Type\*(R" header is \*(L"application/x\-download\*(R" and \*(L"content_disposition\*(R" option value is \*(L"attachment\*(R". Therefore, a browser will ask where to save file. You can provide \*(L"format\*(R" option to change \*(L"Content-Type\*(R" header. .PP \fISupported Options:\fR .IX Subsection "Supported Options:" .ie n .IP """filepath""" 4 .el .IP "\f(CWfilepath\fR" 4 .IX Item "filepath" Path on the filesystem to the file. You must always pass \*(L"filepath\*(R" or \*(L"data\*(R" option .ie n .IP """data""" 4 .el .IP "\f(CWdata\fR" 4 .IX Item "data" Binary content which will be transferred to browser. You must always pass \*(L"filepath\*(R" or \*(L"data\*(R" option .ie n .IP """filename"" (optional)" 4 .el .IP "\f(CWfilename\fR (optional)" 4 .IX Item "filename (optional)" Browser will use this name for saving the file .ie n .IP """format"" (optional)" 4 .el .IP "\f(CWformat\fR (optional)" 4 .IX Item "format (optional)" The \*(L"Content-Type\*(R" header is based on the \s-1MIME\s0 type mapping of the \*(L"format\*(R" option value. These mappings can be easily extended or changed with \*(L"types\*(R" in Mojolicious. .Sp By default \*(L"Content-Type\*(R" header is \*(L"application/x\-download\*(R" .ie n .IP """content_disposition"" (optional)" 4 .el .IP "\f(CWcontent_disposition\fR (optional)" 4 .IX Item "content_disposition (optional)" Tells browser how to present the file. .Sp \&\*(L"attachment\*(R" (default) \- is for dowloading .Sp \&\*(L"inline\*(R" \- is for showing file inline .ie n .IP """cleanup"" (optional)" 4 .el .IP "\f(CWcleanup\fR (optional)" 4 .IX Item "cleanup (optional)" Indicates if the file should be deleted when rendering is complete .PP This plugin respects \s-1HTTP\s0 Range headers. .SH "AUTHOR" .IX Header "AUTHOR" Viktor Turskyi .SH "CONTRIBUTORS" .IX Header "CONTRIBUTORS" Nils Diewald (Akron) Danil Greben (SDSWanderer) .SH "BUGS" .IX Header "BUGS" Please report any bugs or feature requests to Github .SH "SEE ALSO" .IX Header "SEE ALSO" Mojolicious, Mojolicious::Guides, . .PP Copyright 2011 Viktor Turskyi .PP This program is free software; you can redistribute it and/or modify it under the terms of either: the \s-1GNU\s0 General Public License as published by the Free Software Foundation; or the Artistic License. .PP See http://dev.perl.org/licenses/ for more information.