I had to work my way around this as well, and it ended up being that I had to use:
RangedFileResponse module.
Name: django-ranged-response
Version: 0.2.0
Summary: Modified Django FileResponse that adds Content-Range headers.
Author: Spindle
License: MIT
Location: /Users/benjamin/venvs/quickbbs/lib/python3.9/site-packages
Requires: django
Required-by:
And I am using this wrapper, for the download:
def download(request, filename=None):
"""
Replaces new_download.
This now takes http://<servername>/downloads/<filename>?UUID=<uuid>
This fakes the browser into displaying the filename as the title of the
download.
"""
# Is this from an archive? If so, get the Page ID.
d_uuid=request.GET.get("UUID", None)
if d_uuid == None:
d_uuid=request.GET.get("uuid", None)
if d_uuid in ["", None]:
raise Http404
page = request.GET.get('page', None)
if page is None:
download = index_data.objects.filter(uuid=d_uuid,
ignore=False,
delete_pending=False)[0]
else:
print ("Attempting to find page %s in archive" % page)
print("\tDownloading - %s, %s" % (download.fqpndirectory.lower(),
download.name))
movie = download.filetype.is_movie
return respond_as_inline(request,
"%s%s%s" % (
configdata["locations"]["albums_path"],
os.sep,
download.fqpndirectory),
download.name,
ranged=movie)
def respond_as_inline(request, file_path, original_filename, ranged=False):
filename = os.path.join(file_path, original_filename)
if os.path.exists(filename):
mtype, encoding = mimetypes.guess_type(original_filename)
if mtype is None:
mtype = 'application/octet-stream'
with open(filename, 'rb') as fh:
if ranged:
response = RangedFileResponse(request, file=open(filename, 'rb'), as_attachment=False, filename=original_filename)
response["Content-Type"] = mtype
else:
response = HttpResponse(fh.read(), content_type=mtype)
response['Content-Disposition'] = 'inline; filename=%s'% original_filename
return response
else:
print("File not found")
raise Http404
For the web side..
{% if item.filetype.is_movie %}
<video class="video-js" data-setup='{}' controls><source src="/download/{{ item.uuid }}" type="video/mp4"></video>
{% endif %}
Hope that helps. And yes, the python code is intended as a starting place, as it's very specific to my implementation of a web gallery..
But I'm more than happy to try to help…
- Benjamin
On Apr 21, 2021, at 8:10 PM, Thiago Luiz Parolin <thiago.parolin@unesp.br> wrote:try using {% static.. to server your file.Em qua., 21 de abr. de 2021 às 19:44, תמר בביוף <tamar14191@gmail.com> escreveu:Hello everyone:I try to enable a video tag in HTML like this<video width="530" height="440" controls autoplay>
<source src="../static/you.mp4" type="video/mp4"></source>
</video>:My problem is that the video does not run on Django, and looks like a blackRunning on html alone it works,Does anyone know what the problem is? Is not a video tag enough when using Django?--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/db9c1818-3312-45b4-a652-6a2dbc5bb688n%40googlegroups.com.
--Thiago Luiz Parolin--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CANbmKysnyHnW7yz6jL_rBS5xBrdroHmZNKTzn%2Bx2D2Vj0dy8aA%40mail.gmail.com.
No comments:
Post a Comment