2

何が足りないのですか。ディスクにダウンロードされたこのビデオ ファイルを提供しようとすると、ブラウザで内部サーバー エラーが発生し続けます。ここに私のコードがあります: ビュー関数

@view_config(name='download_video')
def dl(request):
    url = request.params.get('url')
    camefrom = request.params.get('came_from')
    path_dir = request.registry.settings['app.download_path']
    result= save_to_disk(url, path_dir)
    if result:
        filename = result['filename']
        filepath = os.path.abspath(os.path.join(path_dir,filename))
        file_exists = os.path.exists(filepath)
        if file_exists:
            res = FileResponse(filepath,content_type='video/mp4')
            res.headers['Content-Length'] = os.path.getsize(filepath)
            res.headers['Content-Disposition'] = 'attachment;filename=%s'%filename
            return res
    request.session.flash(_("Error downloading video, please check your network","danger"))
    return HTTPFound(location=camefrom)

テンプレート

<a tal:attributes="href api.url(api.root, '@@download_video', query={'came_from': request.url,'url':context.video_url})" class="btn">Download</a>

ビデオがダウンロードされ、フォルダーに表示されますが、ブラウザーでトレースバックなしで内部サーバーエラーが発生し続けます

私のアプリは Kotti cms に依存しています

4

1 に答える 1

4

あなたの Pyramid ロギングで何が起こっているのかわかりませんが、ファイルをダウンロードするための私の見解は次のとおりです。私は現在iPhoneを使用しているので、カットアンドペーストしただけですが、アイデアが得られるはずです.

@view_config(route_name="download_view", renderer="")
def server_view1010(request):
    filepath = os.path.join(CFG.home_dir, "static/graphics/imgs/img_sample.jpg")
    if request.storage.exists(filepath):                                                     #there is no overwrite
        response = FileResponse(filepath)
        response.headers['Content-Disposition'] = ("attachment; filename=img_sample.jpg")
        return response
    else:
        return Response("Unable to find: {}".format(request.path_info))
于 2016-08-28T12:10:56.540 に答える