Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Hello there kikuchiyo
A big thank you for you testing, now the code is working

The problem was, I was using plackup -L Shotgun to run the psgi app, and the error I was getting was.

Magic number checking on storable string failed at /usr/lib/x86_64-linux-gnu/perl/5.22/Storable.pm line 420, at /usr/local/share/perl/5.22.1/Plack/Loader/Shotgun.pm line 35. Sometimes I get the error memory

But when I change to just plackup, everything works
here is the final code:

use strict; use warnings; ####use Plack::Response; # doesn't seem to support streaming response use Path::Tiny; use File::MimeInfo; my $app = sub { my $env = shift; my $path_file = 'win.iso'; my $content_type = mimetype($path_file); $content_type = 'application/octet-stream' if not defined $content +_type; 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; } }
again thank you so much for your time and your code

In reply to Re^7: Download big file in chunks with plack response by Thenothing
in thread Download big file in chunks with plack response by Thenothing

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2024-04-18 03:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found