我正在从服务器获取文件内容。服务器包含所有类型的文件,如 json、文本等。
@app.get("myurl")
def get_file(myfilename):
mydata=fetch_file_from_server(myfilename)
headers = {"content-disposition": "attachment; filename=\"{}\"".format(myfilename)}
return Response(content=mydata, media_type="application/json", headers=headers)
我试过
media_type="application/json"
但它似乎只适用于 JSON 文件。
我希望无论扩展名如何都能下载文件。
我目前正在使用
media_type="application/tar+gzip"
,但不确定这是否是正确的方法。