examples for X-Sendfile are not clear (include directive references wrong code)
what URL middlewares catches and what URL it passes as X-Senfile header should be explained.
As an example:
given settings.MEDIA_URL = '/media/'
given a model with file = models.FileField(upload_to='documents'). It will have file.url prefixed with MEDIA_URL and UPLOAD_TO, i.e. /media/documents/ in our example.
given source_url is "/media/documents/", middleware will catch DownloadResponse where file.url starts with "/media/documents/", such as "/media/documents/sample-filename.pdf" => middleware will send "/sample-filename.pdf" to x-sendfile
given destination_url is "/var/lib/media/documents" (notice no trailing backslash) => x-sendfile value will be /var/lib/media/documents/sample-filename.txt
in general, destination_url should match one value configured as XSendFilePath in Apache configuration.
In documentation:
As an example:
settings.MEDIA_URL = '/media/'
file = models.FileField(upload_to='documents')
. It will havefile.url
prefixed with MEDIA_URL and UPLOAD_TO, i.e./media/documents/
in our example.source_url
is"/media/documents/"
, middleware will catch DownloadResponse where file.url starts with"/media/documents/"
, such as"/media/documents/sample-filename.pdf"
=> middleware will send "/sample-filename.pdf" to x-sendfiledestination_url
is"/var/lib/media/documents"
(notice no trailing backslash) => x-sendfile value will be/var/lib/media/documents/sample-filename.txt
destination_url
should match one value configured asXSendFilePath
in Apache configuration.