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?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.