flask send_file&send_from_directory

尽量不要使用send_file(),而使用send_from_directory,后者限定了文件夹,更安全

flask.send_file(filename_or_fp, mimetype=None, as_attachment=False, attachment_filename=None, add_etags=True, cache_timeout=None, conditional=False, last_modified=None)
参数说明
filename_or_fp需要发送的文件
mimetypethe mimetype of the file if provided. If a file path is given, auto detection happens as fallback, otherwise an error will be raised.
as_attachmentet to True if you want to send this file with a Content-Disposition: attachment header.
attachment_filenamethe filename for the attachment if it differs from the file’s filename.
add_etagsset to False to disable attaching of etags.
conditionalset to True to enable conditional responses.
cache_timeoutthe timeout in seconds for the headers.
last_modified
flask.send_from_directory(directory, filename, **options)
参数描述
directorythe directory where all the files are stored.
filenamethe filename relative to that directory to download.
optionsoptional keyword arguments that are directly forwarded to send_file().

参考文献:
http://flask.pocoo.org/docs/0.12/api/#flask.send_from_directory
https://stackoverflow.com/questions/38252955/flask-when-to-use-send-file-send-from-directory?r=SearchResults

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值