微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

为什么我总是从 postgesql 中的 fethcing 数据类型 BLOB 中得到 null

如何解决为什么我总是从 postgesql 中的 fethcing 数据类型 BLOB 中得到 null

我想使用 rest-api python3odoo 中的 postgresql 获取图像,但我无法获取,因为
响应数据始终显示为空。

enter image description here



这是我的模型:

objReturn.length or objReturn.textContent


我使用 from odoo import models,fields class HrAttendanceBreak(models.Model): _name = "hr.attendance.break" _rec_name = 'rec_name' rec_name = fields.Char(string="Record Name",compute='_get_rec_name',store=True) attendance_id = fields.Many2one('hr.attendance',ondelete='cascade',store=True,copy=False,string='Attendance Reference') employee_id = fields.Many2one('hr.employee',string="Employee") jam_istirahat = fields.Datetime(string="Jam Istirahat") x_long_break = fields.Char(string="X,Longitude Break") y_lat_break= fields.Char(string="Y,Latitude Break") concat_break = fields.Char(string="Latlong Break") break_photo = fields.Binary(string='Break Photo',attachment=False) jam_lanjutKerja = fields.Datetime(string="Lanjut Kerja") x_long_resume = fields.Char(string="X,Longitude Resume") y_lat_resume= fields.Char(string="Y,Latitude Resume") concat_resume = fields.Char(string="Latlong Resume") resume_photo = fields.Binary(string='Resume Photo',attachment=False) fields.Binary()break_photo 存储到数据库中。

enter image description here


这是我获取数据的方式:

resume_photo

有人可以帮我吗?

解决方法

在 Odoo 中有一个现有的控制器来检索名为 content_image 的图像,其路由定义如下

[
    '/web/image','/web/image/<string:xmlid>','/web/image/<string:xmlid>/<string:filename>','/web/image/<string:xmlid>/<int:width>x<int:height>','/web/image/<string:xmlid>/<int:width>x<int:height>/<string:filename>','/web/image/<string:model>/<int:id>/<string:field>','/web/image/<string:model>/<int:id>/<string:field>/<string:filename>','/web/image/<string:model>/<int:id>/<string:field>/<int:width>x<int:height>','/web/image/<string:model>/<int:id>/<string:field>/<int:width>x<int:height>/<string:filename>','/web/image/<int:id>','/web/image/<int:id>/<string:filename>','/web/image/<int:id>/<int:width>x<int:height>','/web/image/<int:id>/<int:width>x<int:height>/<string:filename>','/web/image/<int:id>-<string:unique>','/web/image/<int:id>-<string:unique>/<string:filename>','/web/image/<int:id>-<string:unique>/<int:width>x<int:height>','/web/image/<int:id>-<string:unique>/<int:width>x<int:height>/<string:filename>'
]    

所以你可以使用如下:

'/web/image/hr.attendance.break/5/break_photo'
'/web/image/hr.attendance.break/5/resume_photo'

因此在您的控制器中,您将为响应生成这样的 url,浏览器应加载它,如下所示:

@http.route('/api/hr.attendance.break',type='http',auth="none",methods=['GET'],csrf=False)
    def hr_attendance_breake_list(self,**payload):
        model = 'hr.attendance.break'
        ioc_name = model
        model = request.env[self._model].sudo().search(
            [('model','=',model)],limit=1)

        custFields = [
            'id','employee_id','jam_istirahat','jam_lanjutKerja','x_long_break','y_lat_break','break_photo','x_long_resume','y_lat_resume','resume_photo'
            ]
        
        if model:
            domain,fields,offset,limit,order = extract_arguments(payload)
            fields = custFields
            data = request.env[model.model].sudo().search_read(
                domain=domain,fields=fields,offset=offset,limit=limit,order=order)
            if data:
                for item in data:
                    item['break_photo'] = '/web/image/hr.attendance.break/{}/break_photo'.format(item['id'])
                    item['resume_photo'] = '/web/image/hr.attendance.break/{}/resume_photo'.format(item['id'])
                return valid_response(data)
            else:
                return valid_response(data)
        return invalid_response('invalid object model','The model %s is not availablee in the registry.' % ioc_name)

您最终的 json 应如下所示:

{
  "id": 65,"resume_photo": "/web/image/hr.attendance.break/65/resume_photo","break_photo": "/web/image/hr.attendance.break/65/break_photo","employee_id":[
      6,"Muhamed Irsan",],}

您可以在您的网络浏览器中对此进行测试,请注意,如果客户端是移动应用程序或自定义应用程序,则必须使用 url 获取图像。这应该是自动完成的。您必须与您的自定义客户打交道。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。