2016-06-20 6 views
2

私は方法があります:壊れたパイプ試みがビデオをロードするよりも大きい72メガバイト

このコードはビデオをダウンロードしようとしている
startLesson: function(lesson) { 
    var scope = this; 

    scope.getLessonDataFromFile(lesson.id).then(function (data) { 
    scope.mode = 'LESSON'; 
    scope.lesson.name = lesson.filename; 
    scope.lesson.task = data; 
    scope.lesson.taskHash = hash(JSON.stringify(scope.lesson.task)); 
    scope.lesson.flags = []; 
    scope.lesson.score = []; 
    scope.lesson.visibleDescriptions = []; 
    scope.lesson.visibleDescriptionActions = []; 
    scope.lesson.editMode = false; 
    scope.lesson.analysisMode = false; 
    scope.lesson.totalScore = 0; 
    scope.lesson.maxScore = scope.lesson.task.timeslots.length * 15; 
    $("#video")[0].load(); 
    $("#video")[0].addEventListener("canplay", scope.updateDurationOnCanplay, false); 
}); 

は(私はまだ正確な値を決定していないが、それはどこかです33〜72メガバイトの範囲)、特定の値の大きさよりも大きいで、次の処理が行われます

[20/Jun/2016 15:24:18] "GET /lessons/api/lessons/01 HTTP/1.1" 200 6760 
[20/Jun/2016 15:24:19] "GET /media/video/01.mp4 HTTP/1.1" 200 190267623 
[20/Jun/2016 15:24:19] "GET /media/video/01.mp4 HTTP/1.1" 200 688128 
Traceback (most recent call last): 
    File "/usr/lib/python2.7/wsgiref/handlers.py", line 86, in run 
    self.finish_response() 
    File "/usr/lib/python2.7/wsgiref/handlers.py", line 128, in finish_response 
    self.write(data) 
    File "/usr/lib/python2.7/wsgiref/handlers.py", line 217, in write 
    self._write(data) 
    File "/usr/lib/python2.7/socket.py", line 328, in write 
    self.flush() 
    File "/usr/lib/python2.7/socket.py", line 307, in flush 
    self._sock.sendall(view[write_offset:write_offset+buffer_size]) 
error: [Errno 104] Connection reset by peer 
[20/Jun/2016 15:24:19] "GET /media/video/01.mp4 HTTP/1.1" 500 59 
- Broken pipe from ('127.0.0.1', 44686) 

マイAPI:

@staticmethod 
def get(request, lesson_name): 
    data_file_path = os.path.join(VIDEO_ROOT, lesson_name + '.json') 
    data = {} 
    try: 
     with open(data_file_path, 'r') as data_file: 
      data = json.load(data_file) 
    except IOError: 
     data['timeslots'] = [] 
    data['id'] = lesson_name 
    data['filename'] = os.path.join(settings.MEDIA_URL, 'video', lesson_name + '.mp4') 

    return Response(data) 

このような奇妙なエラーの原因は何でしょうか?大きなファイルの場合

+0

あなたはどのウェブサーバを使用していますか?何wsgiハンドラ? –

答えて

2

あなたはDjangoのStreamingHttpResponseを使用する必要があります。

import os 
import mimetypes 
from wsgiref.util import FileWrapper 
from django.http import StreamingHttpResponse 


def get(request, lesson_name): 

    video_path = 'path_to_file' 

    wrapper FileWrapper(open(video_path)) 
    response = StreamingHttpResponse(wrapper, content_type=mimetypes.guess_type(video_path)[0]) 
    response['Content-Length'] = os.path.getsize(video_path) 

しかし - あなたはおそらく、あなたのウェブサーバの設定にいくつかの調整を行う必要があります。 Apache2またはnginxを使用していますか?そして使用中のアプリケーションサーバー。ガンニコーン? Django uWSGI?

関連する問題