Skip to content

fetching binary data of image  #96

@abaysevi

Description

@abaysevi

i was trying to fetch the binary data of an image from the products image_1920

also i am using flask

`@app.route('/products')
def list_products():
try:
# Fetch product data
res = odoo.execute_kw("product.template", "search_read", [], {
'context': {'bin_size': True},
'domain': [],
'fields': ['id', 'name', 'list_price', 'default_code', 'image_1920'],
'limit': 80,
})

    # Extract and decode binary image data (if present)
    products=[]
    for product in res:
        if product.get('image_1920'):
            try:
                print(type(product.get("image_1920")))
                image_data = base64.b64decode(product['image_1920'])
            except Exception:
                try:
                    image_data = base64.urlsafe_b64decode(product['image_1920'])
                except Exception:
                    image_data = None  # Handle unknown encoding

            product['image_data'] = image_data
            products.append(product)
    return jsonify({"message": "data received", "data": products})

except Exception as e:
    return jsonify({'fetching data': False, 'message': str(e)})`
    
    
    in this the response i get for the image_1920 
    
    is like a string with the size of the image 

33.53 Kb
25.06 Kb
30.60 Kb
49.69 Kb

like this

{'id': 41, 'name': 'Whiteboard Pen', 'list_price': 1.2, 'default_code': 'CONS_0001', 'image_1920': '44.87 Kb'}

i need the binary data

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions