title: Python - Django: Streaming video/mp4 file using HttpResponse
body: <p>I'm using Python2.7, <code>django==1.7</code> and <code>uwsgi</code> for streaming video/mp4 file to <code>iPhone</code> player.</p>
  
  <p>My code is as below:</p>
  
  <pre><code>def stream(request):
       with open('/path/video.mp4', 'r') as video_file:
          response = HttpResponse(video_file.read(), content_type='video/mp4')
          response['Content-Disposition'] = 'inline; filename=%s' % 'video.mp4'
          return response
       video_file.close
  </code></pre>
  
  <p>When i use some small video (less than 1MB), it streams in browser, but in iPhone palyer i have this error: </p>
  
  <blockquote>
    <p>[uwsgi-http key: 127.0.0.1:8008 client_addr: 192.168.0.172
    client_port: 14563] hr_write(): Broken pipe [plugins/http/http.c line
    564]</p>
  </blockquote>
  
  <p>And when the video size is more that 5MB, it doesn't stream in both (means browser and iPhone player) with same error.</p>
  
  <p>I tried to do that by chunk chunk returning using StreamHttpRespose as below:</p>
  
  <pre><code>def read(chunksize=8192):
      with open('/path/video.mp4', 'rb') as video_file:
          byte = video_file.read(chunksize)
          while byte:
              yield byte
  
  return StreamingHttpResponse(read(), content_type='video/mp4')
  </code></pre>
  
  <p>But there is the same error: <code>Broken pipe</code>.</p>
  
  <p>fyi I can stream pdf and image files. This problem is only with mp4 files.  And also i changed the content_type to 'video-mpeg', the browser downloaded that, while i want to prevent file downloading.</p>
  
  <p>What's your idea? Any solution!!?</p>