Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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:


# 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.

In reply to Sending files with XSendFile by rpnoble419

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • 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, 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, 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others cooling their heels in the Monastery: (4)
    As of 2018-04-24 23:54 GMT
    Find Nodes?
      Voting Booth?