繁体   English   中英

Python Flask:从其他链接发送文件

[英]Python Flask: send file from other link

如何从请求的结果发送文件,如果我将文件写入它可以工作的文件夹,但写入需要时间。 但我想要的是直接从请求结果发送。 对不起,我的英语不好

 import requests

 def get(cls, date: str, date_end: str, office_in_charge: str):
        user = get_jwt_identity()
        url = "http://localhost:9090/jasperserver/rest_v2/reports/reports/interactive/DTR.pdf"
        r = requests.get(url,
                         params={
                             'username': 'jasperadmin',
                             'password': 'jasperadmin',
                             'p1': user,
                             'p2': user,
                             'date': date,
                             'date_end': date_end,
                             'office_in_charge': office_in_charge
                         }
                         , allow_redirects=True)

        return send_file(r.content, as_attachment=True, mimetype='application/pdf')

这可能对您有用:

 import requests, io

 def get(cls, date: str, date_end: str, office_in_charge: str):
        user = get_jwt_identity()
        url = "http://localhost:9090/jasperserver/rest_v2/reports/reports/interactive/DTR.pdf"
        r = requests.get(url,
                         params={
                             'username': 'jasperadmin',
                             'password': 'jasperadmin',
                             'p1': user,
                             'p2': user,
                             'date': date,
                             'date_end': date_end,
                             'office_in_charge': office_in_charge
                         }
                         , allow_redirects=True)

        return send_file(
                     io.BytesIO(r.content),
                     attachment_filename='report.pdf',
                     mimetype='application/pdf'
               )

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM