Django do not include a HTTP Ranged Response. 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.
Forked originally from a project that only handles local files This fork also include Ranged Responses from open Google Storage Blobs
~Maintained
- django >= 3.2
pip install -e git://github.com/cluster311/django-ranged-fileresponse#egg=django-ranged-fileresponse==0.2.0
from ranged_fileresponse.local import RangedLocalFileResponse
def some_proxy_view(request):
filename = 'myfile.wav'
response = RangedLocalFileResponse(request, open(filename, 'r'), content_type='audio/wav')
response['Content-Disposition'] = 'attachment; filename="%s"' % filename
return response
from ranged_fileresponse.google import RangedGoogleBlobResponse
def some_proxy_view(request):
filename = 'myfile.wav'
response = RangedGoogleBlobResponse(
request,
"https://storage.googleapis.com/parlarispa-app-files/audios/s02e38-adria-mercader.mp3", # the media URL
content_type='audio/wav'
)
response['Content-Disposition'] = 'attachment; filename="%s"' % filename
return response
from django.dispatch import receiver
from ranged_fileresponse import ranged_file_response_signal
@receiver(ranged_file_response_signal)
def chunk_received(sender, uid, start, reloaded, finished, **kwargs):
# do something with this data
# save_stats(uid=uid, start=start, reloaded=reloaded, finished=finished)
See the CONTRIBUTING.md file on how to contribute to this project.
See the CONTRIBUTORS.md file for a list of contributors to the project.
The changelog can be found in the CHANGELOG.md file.
- Maintaining
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 [email protected]
django-ranged-fileresponse is made available under the MIT license. See the LICENSE file for more info.