0

プログラムでパワーポイントを作成し、ユーザーが最後にダウンロードできるようにするWebアプリでPython-pptxを使用しています。人々は画像などをアップロードでき、それをパワーポイントに挿入します。

うまく機能しますが、現在、PowerPoint を「静的」フォルダーに保存し、そのファイル パスを使用してダウンロード リンクを作成しています。

理想的には、ファイルをサーバーに保存しないでください。これは、機密情報に関するプライバシーの問題を防ぐためです。人々がログインする必要がなかったら、それも素晴らしいことです。パワーポイントを作成するためのシンプルで安全な方法です。

send_file を無駄に動作させようとしました。私はそれが解決策だと思います。

これが私が試したことです:

prs = Presentation()
file_name = 'static/' + file_name + '.pptx'

root_dir = os.path.dirname(os.getcwd())
path = os.path.join(root_dir, 'project', 'static', 'test.pptx')


return send_file(prs, as_attachment=True)

# also tried:

# return send_file(path, mimetype='applicationvnd.openxmlformats-officedocument.presentationml.presentation', as_attachment=True)

# which loads the page, but doesn’t trigger a download,just loads a blank page.
# plus, it is referencing a file path which means the file was saved on the server

助けていただければ幸いです!初めてのフラスコアプリです!

前もって感謝します!

4

1 に答える 1