@http.route('/robot/filedownload/string:robot_id', type='http', auth="user", methods=['GET'], csrf=False)
def download_file(self, redirect=None, robot_id=False, **kw):
robot = http.request.env['robot'].search([("id", "=", int(robot_id))])
if not robot:
dic = {"result": "fail", "msg": "robot does not exist"}
return json.dumps(dic)
filename = robot.robot_filepath + '\' + robot.name + '.zip'
print(filename) # E:\python_project\Robot\server\robots\打开百度\打开百度.zip
try:
# filename = r'E:\python_project\Robot\server\robots\打开百度\config.ini'
# return http.send_file(filename, filename='baidu.ini',
return http.send_file(filename, filename='baidu.zip',
as_attachment=True)
except Exception as e:
print("导出文件出错:", e)
resp = {"result": "fail", "msg": e}
return json.dumps(resp)
使用odoo.http下的send_file方法,遇到压缩文件时(zip文件)无法传回前端。