generate blob url for file field

refers to this SO question

django 3.2.8; safari Version 14.0.3 (16610.4.3.1.7)

for mp4 and mov, safari does not work, chrome and opera does.

Hi there, I am trying to build a simple video app with django on my local machine.

class Video(models.Model):
	author = models.ForeignKey(User, on_delete=models.CASCADE)
	thumbnail = models.ImageField(upload_to='thumbnail', blank=True, null=True)
	file = models.FileField(upload_to='video', validators=[FileExtensionValidator(allowed_extensions=['mov', 'MOV','avi','mp4', 'MP4','webm','mkv'])])

list view

{% for video in page_obj.object_list %}
    <video width="400" 
    height="350" 
    controls 
    {% if video.thumbnail %}
    poster="{{ video.thumbnail.url }}"
    {% endif %}
    >
    <source src=
    "{{ video.file.url }}"
        type="video/mov">
    </video>
{% endfor %}

Video is not playing on Safari.

Failed to load resource: Plug-in handled load

in terminal

[20/Dec/2021 03:14:16,147] - Broken pipe from ('127.0.0.1', 50812)

I wonder why this happens, will be grateful for your help.


what I have tried

add raw="true" to video tag

did not work, still the same result

transcoding video to web optimised by handbrake

some videos that did not work on Chrome and Opera started to work 
But, not for Safari

tries to embed an YouTube iframe

always works on safari

I suspect the issue is on file server, which I served the video as a file. Safari and chrome requires the video to be served as blob, is there a way to server file field as blob? ,I wonder if there is a way to do it, appreciate for your help.

Side note: This question is one of those where I’m glad to be reading this forum. I had never even heard of blobs in the context of a web protocol until now. (For those with the same lack of knowledge, see File API)

In a production environment, your static and media files should be served by your web server and not Django.

So what web server is your target environment? That’s the configuration issue I’d be looking to address. For example, if you’re running your app under Nginx, I’d be looking for a way to configure Nginx to serve blobs.

(Having said that, a cursory review of the nginx docs doesn’t give me any specific clues in that direction. You might try something along the lines of using default_type and/or sendfile.)

1 Like