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):

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

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