Hello monks, I have been banging my head against a problem for a day, so I have finally decided to ask for a bit of help from the community.
Basic premise: I want to stream files such as MP3's and video files from a Perl script. It mostly works (should be dead-brained easy), but I'm having an infuriating set of issues that I think are related, and are probably due to the HTTP headers. Here is the code, then I will explain the issue in more detail:
my $file = "/path/to/file.mp3";
my $filesize = -s "$file";
print $cgi->header( -type => "audio/mp3",
-Content_length => "$filesize",
-content_disposition => "attachment; filename=$
+params->{cgi}->{fileId}.$params->{cgi}->{fileType}"); #This has been
+tried with -content_disposition and without
open(FILE, "$file");
binmode(FILE);
binmode(STDOUT);
while (<FILE>) {
print;
}
close(FILE);
Here are the issues:
- When you try to download the file directly, it never shows the time remaining for the download to complete.
- When trying to stream the file into either a flash based control like the Longtail Player or a plugin like Quicktime, the file basically has to be completely downloaded before it starts playing. This isn't the case for files that the webserver serves to my knowledge
I've looked at the headers, and they look sane. They have all the options I've specified correctly it seems, I just don't know what I'm doing wrong. Anyone have any thoughts on how I can troubleshoot this?