Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fetching binary data of image #96

Open
abaysevi opened this issue Feb 28, 2024 · 0 comments
Open

fetching binary data of image #96

abaysevi opened this issue Feb 28, 2024 · 0 comments
Labels

Comments

@abaysevi
Copy link

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

@abaysevi abaysevi added the bug label Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant