3

認証されたユーザーに提供する必要がある画像、ビデオなどの静的ファイル (アプリケーションを介してアップロードされる) のセットがあります (つまり、Cookie はセッションで認証済みとして登録されます)。

これらのファイルは別個のものであり、css、javaacript などの他のメディア静的ファイルとはまったく関係ありません。

認証が必要な静的ファイルがかなり大きいことを考えると、それらを提供する最も効率的な方法は何だろうと思っていました (ところで、私は wsgi を使用しています)。

現在、私はこれを持っています:

def return_large_file(request, p_filename):
    """                                                                         
    Send a file through Django without loading the whole file into              
    memory at once. The FileWrapper will turn the file object into an           
    iterator for chunks of 8KB.                                                 
    """
    if not os.path.exists(p_filename):
        raise Exception('File %s does not exist!')

    try:
        _content_type = mimetypes.guess_type(p_filename)
    except:
        _content_type = 'application/octet-stream'

    wrapper = FileWrapper(file(p_filename))
    response = HttpResponse(wrapper, content_type=_content_type)
    response['Content-Length'] = os.path.getsize(p_filename)
    return response
4

1 に答える 1

1

私は現在、あなたが上で使用しているものと同様の機能を使用しています。

パフォーマンス/効率が問題になると、Apachemod-auth-externalを使用して特定のファイルのカスタム認証を行うことを考えていました。

私はこの答えを私の経験に基づいてではなく、私自身の研究が私を導いた場所に提供していることに注意してください。

于 2011-07-13T21:06:02.593 に答える