Odoo14小程序获取图片url

直接上代码:

from odoo.addons.web.controllers import main as web
from odoo import http


class GetImages(http.Controller):

    @http.route('/get_imgae/', methods=['POST', 'GET'], type='http', auth="public", cors="*", csrf=False)
    def get_imgae(self, **kw):


        model = kw.get("model")     # 模型名
        id = kw.get("id")   # 记录id
        field = kw.get("field")     # 字段名

        status, headers, image_base64 = http.request.env['ir.http'].sudo().binary_content(model=model, id=id, field=field, default_mimetype='image/png')

        return web.Binary._content_image_get_response(status, headers, image_base64)

 使用方式:

  http://192.168.75.129:8069/get_imgae?model=th_per_management&id=11935&field=sample_image

posted @ 2022-06-05 09:59  手可摘星辰。  阅读(224)  评论(0编辑  收藏  举报