1Mojolicious::Plugin::ReUnsdeerrFCiolnet(r3i)buted Perl DMoocjuomleinctiaotuiso:n:Plugin::RenderFile(3)
2
3
4
6 Mojolicious::Plugin::RenderFile - "render_file" helper for Mojolicious
7
9 # Mojolicious
10 $self->plugin('RenderFile');
11
12 # Mojolicious::Lite
13 plugin 'RenderFile';
14
15 # In controller
16 $self->render_file('filepath' => '/tmp/files/file.pdf'); # file name will be "file.pdf"
17
18 # Provide any file name
19 $self->render_file('filepath' => '/tmp/files/file.pdf', 'filename' => 'report.pdf');
20
21 # Render data from memory as file
22 $self->render_file('data' => 'some data here', 'filename' => 'report.pdf');
23
24 # Open file in browser(do not show save dialog)
25 $self->render_file(
26 'filepath' => '/tmp/files/file.pdf',
27 'format' => 'pdf', # will change Content-Type "application/x-download" to "application/pdf"
28 'content_disposition' => 'inline', # will change Content-Disposition from "attachment" to "inline"
29 'cleanup' => 1, # delete file after completed
30 );
31
33 Mojolicious::Plugin::RenderFile is a Mojolicious plugin that adds
34 "render_file" helper. It does not read file in memory and just
35 streaming it to a client.
36
38 "render_file"
39 $self->render_file(filepath => '/tmp/files/file.pdf', 'filename' => 'report.pdf' );
40
41 With this helper you can easily provide files for download. By default
42 "Content-Type" header is "application/x-download" and
43 "content_disposition" option value is "attachment". Therefore, a
44 browser will ask where to save file. You can provide "format" option to
45 change "Content-Type" header.
46
47 Supported Options:
48
49 "filepath"
50 Path on the filesystem to the file. You must always pass "filepath"
51 or "data" option
52
53 "data"
54 Binary content which will be transferred to browser. You must
55 always pass "filepath" or "data" option
56
57 "filename" (optional)
58 Browser will use this name for saving the file
59
60 "format" (optional)
61 The "Content-Type" header is based on the MIME type mapping of the
62 "format" option value. These mappings can be easily extended or
63 changed with "types" in Mojolicious.
64
65 By default "Content-Type" header is "application/x-download"
66
67 "content_disposition" (optional)
68 Tells browser how to present the file.
69
70 "attachment" (default) - is for dowloading
71
72 "inline" - is for showing file inline
73
74 "cleanup" (optional)
75 Indicates if the file should be deleted when rendering is complete
76
77 This plugin respects HTTP Range headers.
78
80 Viktor Turskyi <koorchik@cpan.org>
81
83 Nils Diewald (Akron) Danil Greben (SDSWanderer)
84
86 Please report any bugs or feature requests to Github
87 <https://github.com/koorchik/Mojolicious-Plugin-RenderFile>
88
90 Mojolicious, Mojolicious::Guides, <http://mojolicio.us>.
91
92 Copyright 2011 Viktor Turskyi
93
94 This program is free software; you can redistribute it and/or modify it
95 under the terms of either: the GNU General Public License as published
96 by the Free Software Foundation; or the Artistic License.
97
98 See http://dev.perl.org/licenses/ for more information.
99
100
101
102perl v5.28.1 2017-09-24Mojolicious::Plugin::RenderFile(3)