您的位置:首页 > 编程语言 > Go语言

Django文件下载配置

2020-07-09 01:32 155 查看

HttpResponse

response =  HttpResponse(content=流, content_type="文件的媒体类型")
# 下载使用的
response["Content-Disposition"] = "attachment;filename=a.jpg"
return response

FileResponse

# as_attachment = False : false代表在线预览, true 代表下载
# filename 设置下载的文件名
# streaming_content 设置 下载的内容,值必须拥有 read() 方法
# 如果 streaming_content 设置的内容没有 read() 方法,必须设置成 可迭代的对象

return FileResponse(as_attachment=False, filename="a.jpg", streaming_content=io.BytesIO(photo))
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: