Note that there are some explanatory texts on larger screens.

plurals
  1. POFirst 8 bytes are always wrong when downloading a file from my script
    text
    copied!<p>I have a Mojolicious Lite script that "gives out" an executable file (user can download the file from the script's URL). I keep encoded data in an inline template in DATA section, then encode it and render_data.</p> <pre><code>get '/download' =&gt; sub { my $self = shift; my $hex_data = $self-&gt;render_partial( 'TestEXE' ); my $bin_data; while( $hex_data =~ /([^\n]+)\n?/g ) { $bin_data .= pack "H".(length $1), $1; } my $headers = Mojo::Headers-&gt;new; $headers-&gt;add( 'Content-Type', 'application/x-download;name=Test.exe' ); $headers-&gt;add( 'Content-Disposition', 'attachment;filename=Test.exe' ); $headers-&gt;add( 'Content-Description', 'File Transfer'); $self-&gt;res-&gt;content-&gt;headers($headers); $self-&gt;render_data( $bin_data ); }; __DATA__ @@ TestEXE.html.ep 4d5a90000300000004000000ffff0000b8000000000000004000000000000000 00000000000000000000000000000000000000000000000000000000b0000000 0e1fba0e00b409cd21b8014ccd21546836362070726f6772616d2063616e6e6f .... </code></pre> <p>When I run this locally (via built in webserver on <a href="http://127.0.0.1:3000/" rel="nofollow">http://127.0.0.1:3000/</a>, Win7) I get the correct file (size and contents). But when I run it in CGI mode on shared hosting (Linux), it comes back with correct size, but first 8 bytes of the file are always incorrect (and always different). The rest of the file is correct.</p> <p>If in my sub i specify <code>$hex_data</code> instead of <code>$bin_data</code> I get what suppose to be there.</p> <p>I'm at lost.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload