Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I installed the apache dev headers:

sudo apt-get install apache2-prefork-dev

Downloaded and compiled the module as outlined here: http://tn123.ath.cx/mod_xsendfile/

Added the following line to /etc/apache2/mods-available/xsendfile.load:

LoadModule xsendfile_module /usr/lib/apache2/modules/mod_xsendfile.so

Added this to my VirtualHost:

<VirtualHost *:80>
    XSendFile on
    XSendFilePath /path/to/protected/files/

Enabled the module by doing:

sudo a2enmod xsendfile

Then I restarted Apache. Then this code still just provides me with an empty file with 0 bytes:

file_path = '/path/to/protected/files/some_file.zip'
file_name = 'some_file.zip'
response = HttpResponse('', mimetype='application/zip')
response['Content-Disposition'] = 'attachment; filename=%s' % smart_str(file_name)
response['X-Sendfile'] = smart_str(file_path)
return response

And there is not in the Apache error log that pertains to XSendFile. What am I doing wrong?

share|improve this question
    
What do the headers look like that are received by the client? Have you tried setting a more verbose log level (e.g., LogLevel debug)? –  larsks Apr 21 '12 at 0:45

1 Answer 1

I got my code to work. The only difference is:

def serve_file(request, file):
    response = HttpResponse(mimetype='application/force-download')
    response['Content-Disposition'] = 'attachment; filename="%s"' % smart_str(os.path.basename(_(file.file.name)))
    response['X-Sendfile'] = smart_str(_(file.file.path))
    # It's usually a good idea to set the 'Content-Length' header too.
    # You can also set any other required headers: Cache-Control, etc.
    return response
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.