Skip to content
This is a modified FileResponse that returns `Content-Range` headers with the HTTP response, so browsers (read Safari 9+) that request the file, can stream the response properly.
Python
Branch: master
Clone or download
Pull request Compare This branch is 6 commits ahead of wearespindle:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github
ranged_fileresponse
tests
.gitignore
.travis.yml
CHANGELOG.md
CONTRIBUTING.md
CONTRIBUTORS.md
LICENSE
README.md
setup.cfg
setup.py
tox.ini

README.md

django-ranged-fileresponse

Build Status

If you're in the situation that you have an authenticated Django view that returns files for download, you may have noticed that Safari 9.x doesn't play audio files properly when returning audio-files. The reason is that Safari sends a HTTP_RANGE request header and expects a proper Content-Range response header in return. There is a Django ticket for this, however no indication that this feature will be implemented soon.

The original suggested fix applies the code to Django's static view. This is a packaged version of that fix, but uses a modified FileResponse, instead of applying it to Django's static view.

Status

Maintained

Usage

Requirements

  • django >= 1.4

Installation

pip install django-ranged-fileresponse

Running

from ranged_fileresponse import RangedFileResponse

def some_proxy_view(request):
    filename = 'myfile.wav'
    response = RangedFileResponse(request, open(filename, 'r'), content_type='audio/wav')
    response['Content-Disposition'] = 'attachment; filename="%s"' % filename
    return response

Signals

from django.dispatch import receiver
from ranged_fileresponse import RangedFileResponse, ranged_file_response_signal

@receiver(ranged_file_response_signal, sender=RangedFileResponse)
def chunk_received(sender, uid, start, reloaded, finished, **kwargs):
    # do something with this data
    # save_stats(uid=uid, start=start, reloaded=reloaded, finished=finished)

Contributing

See the CONTRIBUTING.md file on how to contribute to this project.

Contributors

See the CONTRIBUTORS.md file for a list of contributors to the project.

Roadmap

Changelog

The changelog can be found in the CHANGELOG.md file.

In progress

  • Maintaining

Future

  • Compatibility

Get in touch with a developer

If you want to report an issue see the CONTRIBUTING.md file for more info.

We will be happy to answer your other questions at opensource@wearespindle.com

License

django-ranged-fileresponse is made available under the MIT license. See the LICENSE file for more info.

You can’t perform that action at this time.