Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet

I have this on my website:


I try to update the product image (image_medium) on a product.id

Here is my code (xml):

<div class="form-group" style="margin-left: 14px;">

<img itemprop="image" class="img img-responsive" t-att-src="website.image_url(product, 'image_medium', None if product_image_big else '300x300')"/>
<input class="input-file profileChooser" id="fileInput" type="file" name="image_medium" onchange="validateProfileImg();"/>


</div>

(controller):

@http.route(['/my/test/<int:product>'], type='http', auth="user", website=True)
def products_followup(self, product=None, redirect=None, **post):
product = request.env['product.template'].browse([product])
try:
product.check_access_rights('read')
product.check_access_rule('read')
except AccessError:
return request.website.render("website.403")
values = {
'error': {},
'error_message': [],
}
if post:

vals = {}
if post['image_medium']:
values.update({'image': base64.encodestring(post['image_medium'].read())})
request.registry['product.template'].write(request.cr, request.uid, [product.id], vals)
product.sudo().write(post)
values.update(post)
if redirect:
return request.redirect(redirect)
return request.redirect('/my/home')

return request.website.render("website_portal_sale.products_followup", {
'product': product.sudo(),
})


Now when I post the image (local file) , I get this error:

AttributeError: 'file' object has no attribute 'decode'


Can someone help me?

thank you.

Avatar
Verwerfen
Verknüpfte Beiträge Antworten Ansichten Aktivität
2
Sept. 18
3324
0
Juni 17
3795
3
Apr. 25
2034
2
Jan. 25
3146
0
Okt. 23
1510