See the section Delayed Response and Streaming Body in the PSGI specification.
What you want is something like this (untested):
use strict;
use warnings;
####use Plack::Response; # doesn't seem to support streaming response
use Path::Tiny;
use File::MimeInfo;
sub return_psgi {
my $self = shift;
my $path_file = shift;
my $content_type = mimetype($path_file);
$content_type = 'application/octet-stream' if not defined $content
+_type;
my $content = path($path_file);
my $content_download = $content->slurp;
require File::Spec::Unix;
my $basename = $path_file;
$basename =~ s|\\|/|g;
$basename = ( File::Spec::Unix->splitpath($basename) )[2];
$basename =~ s|[^\w\.-]+|_|g;
return sub {
my $responder = shift;
my $writer = $responder->(
[ 200, [
'Content-Type' => $content_type,
'Content-Disposition' => qq[attachment; filename="$
+basename"],
]
]
);
open (FILE, "< $path_file") or die "can't open $path_file: $!"
+;
binmode FILE;
local $/ = \102400;
while (<FILE>) {
$writer->write($_);
}
$writer->close();
close FILE;
}
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|