http://www.perlmonks.org?node_id=1000255

rpnoble419 has asked for the wisdom of the Perl Monks concerning the following question:

Has anyone tried out the Apache module for XSendFile with Perl? I installed it and it seams to be working (Apache started). I have tried a few attempts using the following Perl code to download a file:
print "X-Sendfile: C:\\Path\\to\\file\\video\\"; print "Content-Type:application/octet-stream; name=\"File-12.mp4\"\r\n +"; print "Content-Disposition: attachment; filename=\"File-12.mp4\"\r\n\n +"; print "\n\n"; exit;

I'm not getting the video to download. In Chrome, I not getting the correct header, and Apache is giving me a 404 error when I run the script. I'm trying to serve large video files after the user passes muster in my app. Here is the sample PHP code I based my Perl script on.

<?php ... if ($user->isLoggedIn()) { header("X-Sendfile: $path_to_somefile"); header("Content-Type: application/octet-stream"); header("Content-Disposition: attachment; filename=\"$somefile\""); exit; } ?> <h1>Permission denied</h1> <p>Login first!</p>

I tried to serve the file via Perl but the file is over 1.7GB and it hangs my server with an out of memory error.

Update: Sorry where are my manners. As always, Thank You for your time and help...

Update with Solution: I had two things wrong. The first was my Apache Config. The config must look like this in-order to work:

httpd.conf

# enable xsendfile XSendFile On XSendFilePath C:/Path/To/Files/

The actual XsendFile On can be located in a vhost block as well, but the XSendFilePath must be located in the httpd.conf file.

My Perl header was in the wrong order. It needs to look like this:

my $file = "C:/Patch to file/FiletoSend.mp4"; my $filesize = -s $file; print "Content-Type:video/mp4\n"; # remove comment below to make file download. Add the comment to strea +m data to player #print "Content-Disposition: attachment; filename=\"FiletoSend.mp4\"\n +"; print "Content-Length: $filesize\n"; print "X-Sendfile: $file"; print "\n\n"; exit;

Now my system can stream the video after the user has been authenticated and I can create a one-time use URL.