0

I'm trying to return images/videos to a user via X-sendfile on my Flask/Apache2 web app but can't seem to manage it.

In my apache site configuration I have:

<VirtualHost *:443>

<Directory /home/me/Documents/PhotoSite/>
                XSendFile on
                XSendFilePath /path/to/media/
                Options FollowSymLinks
                AllowOverride None
                Require all granted
</Directory>

</VirtualHost>

And in the flask app:

from flask import Flask, send_file

app = Flask(__name__)
app.config['USE_X_SENDFILE'] = True

@app.route('/testreturn')
def returntest():

    dir = "/path/to/media/"
    file = "actual_file.mp4"
    filetosend = dir + file 

    return send_file(filetosend)

And then in a simple HTML file:

<video width="100%" controls autoplay>
  <source src="https://serverurl.com/testreturn" type="video/mp4">
</video>

Upon running 'apache2ctl -M', xsendfile_module (shared) is there so it should be configured properly and developer tools in chrome shows the request:`

Response Headers:
....
X-Sendfile: /path/to/media/actual_file.mp4

So it should be sent but no video plays or anything on the website. Does anyone spot what I'm doing wrong? No errors are coming up on apache2's error.log

If I remove app.config['USE_X_SENDFILE'] = True from the flask app, the files will send correctly (now not using x-sendfile) but they are incredibly slow to load and have a low frame rate so I thought letting apache2 return the files instead of flask by using x-sendfile would solve this

Flask (python3.8), Apache2.4, Ubuntu 20.04

Thanks!

James Watson
  • 35
  • 1
  • 4

0 Answers0