Odoo通过Web url获取附件文件 - xiaohao0576/odoo-doc GitHub Wiki

Odoo有一个controller,以 /web/content开头,可以访问任何模型下的Binary 或 Image 类型的字段内容

当然包括ir.attachment模型,并且ir.attachment是默认的模型,raw是默认的字段

如果想获取ir.attachment模型中存储的文件,直接访问 /web/content/<int:id>就可以了

如果在访问的时候想自定义文件名,可以访问 /web/content/<int:id>/<string:filename>

    @http.route([
        '/web/content',
        '/web/content/<string:xmlid>',
        '/web/content/<string:xmlid>/<string:filename>',
        '/web/content/<int:id>',
        '/web/content/<int:id>/<string:filename>',
        '/web/content/<string:model>/<int:id>/<string:field>',
        '/web/content/<string:model>/<int:id>/<string:field>/<string:filename>',
    ], type='http', auth='public', readonly=True)

参考源码 : https://github.com/odoo/odoo/blob/18.0/addons/web/controllers/binary.py#L62-L88

⚠️ **GitHub.com Fallback** ⚠️