0

I'm using Python2.7, Django==1.7 and uwsgi.

I need to stream a mp4 file using HttpResponse for rendering in html (e.g. video tag) as below:

def test(request):
    return render(request,
                  'shared/test.html',
                  {'video_url': BASE_URL + '/stream_video/'})


def stream_video(request):
    path = '/var/www/test/video_file.mp4'
    video_file = open(path, 'r')
    response = HttpResponse(video_file, content_type='video/mp4')
    response['Content-Length']    = os.path.getsize(path)
    return response

And I run my Django app via uwsgi with this parameters:

uwsgi --http :8000 --chdir /var/www/test --module test.wsgi --chunked-input-timeout 40000 --post-buffering 12829000 --buffer-size 12829000 --post-buffering-bufsize 12829000 --fastrouter-buffer-size 12829000 --http-buffer-size 12829000

In small videos (less than 1MB) it works correctly, but in other case i have uwsgi error as below:

uwsgi_response_write_body_do(): Connection reset by peer [core/writer.c line 331] during GET /stream_video/ (192.168.0.224) IOError: write error

As you see, I set all buffer-size parameters to solve this problem. But it doesn't work for me.

What's your idea?

Aida.Mirabadi
  • 996
  • 4
  • 10
  • 27
  • Possible duplicate of [sending-video-as-response-in-django](http://stackoverflow.com/questions/10493181/sending-video-as-response-in-django) – dkol Oct 26 '15 at 10:34
  • @dkol Thanks for your comment, but in that question the video file is attachment. i need to stream that. see another question related to StreamHttpResponse http://stackoverflow.com/questions/33208849/python-django-streaming-video-mp4-file-through-httpresponse – Aida.Mirabadi Oct 26 '15 at 10:46

0 Answers0