odoo16 Controller文件上传

服务端

复制代码
 1 import logging
 2 import json
 3 from base64 import b64encode
 4 from odoo import http, SUPERUSER_ID, _
 5 from odoo.http import request
 6 
 7 _logger = logging.getLogger(__name__)
 8 
 9 class Main(http.Controller):
10 
11     @http.route('/douban/film', auth='none', type='http', csrf=False)
12     def douban_film(self, **post):
13         indata = {
14             'name':post.get('name'),
15             'detail_url': post.get('detail_url'),
16             'info': post.get('info'),
17             'theme': b64encode(post.get('theme').read())
18         }
19         request.env['douban.film'].sudo().create(indata)
20 
21         rstr = json.dumps({'ss':0}, sort_keys=False, indent=4, separators=(',', ':'), ensure_ascii=False)
22         return rstr
复制代码

Python客户端

复制代码
 1 import requests
 2 def main():
 3     data = {
 4         'name': 'test',
 5         'detail_url': 'detail_url',
 6         'info': 'info',
 7         # 'theme': open('lll.png', 'rb')
 8     }
 9 
10     r = requests.post('http://localhost:8069/douban/film', data=data, files={'theme': open('lll.png', 'rb')})
11     print(r.text)
12 
13 if __name__ == '__main__':
14     main()
复制代码

 

posted @   看一百次夜空里的深蓝  阅读(92)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示