static html page has no header..
every time you make a http request headers are sent before the content
a static html page on your local harddrive does not test how http works
Anyway, this works for me
#!/usr/bin/perl --
use CGI::Carp qw/ fatalsToBrowser /;
use strict;
use warnings;
use IO::Handle;
use CGI;
use autodie qw/ open /;
Main( @ARGV );
exit( 0 );
sub Main {
STDOUT->autoflush;
my $cgi = CGI->new;
PrintHeadersAndContent ( $cgi );
}
sub PrintHeadersAndContent {
use autodie qw/ open /;
my( $cgi ) = @_;
my $filename = q{/harcoded/path/to/one/file};
open my($fh),'<:raw', $filename; ## or die by autodie
my $attachment = 'Juice.mp4';
my $size = -s $filename;
my $begin = 0;
my $end = $size;
if( my $httprange = $cgi->http('range') ){
if( $httprange =~ /bytes=(\d+)(?:-(\d*))?/i ){
my $from = $1;
my $to = $2;
$from and $begin = $from;
$to and $end = $to;
}
}
my $range = "$begin-$size/$size";
print $cgi->header(
-nph => 1,
-type => "application/x-vlc-plugin",
-attachment => $attachment,
-Accept_Ranges => 'bytes',
-Content_Length => $size,
-Content_Range => $range,
-Content_Transfer_Encoding => 'binary',
);
my $numbytes = 1024*16;;
seek $fh, $begin, 0;
my $curr = $begin;
while(not eof $fh) {
my $readed = read $fh, my($data) , $numbytes;
print STDOUT $data;
$readed == $numbytes
or warn "Only read($readed) but wanted($numbytes): $! ## $
+^E ";
$curr += $numbytes;
if( $curr + $numbytes > $size ){
$numbytes = $size - $curr;
}
}
close $fh;
}
__END__
-
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.