Skip to Content
Menu
This question has been flagged
1 Odpoveď
16468 Zobrazenia

Hello Folks


After uploading an image on ODOO site and display it on the webpage

We have an image location like this


https://www.domain_name/web/image/565


the only difference with another uploaded image is the ID number


Where does ODOO store that image ?


in the server  file system ? where ?

in the PostgreSQL database ?


I've used find to search elsewhere on the entire server whithout success

may be it's an hidden directory ?


the problem is thant when I restore my database from one server to another

The images of website are not available

I think I need to restore in the same way the  image folder, but from where ?


where am I wrong ?


thank you for your help

Avatar
Zrušiť
Best Answer

Hello,

Template to attach image file in your website form should contain following code:

 <form action="/save/my/profile" method="post" enctype="multipart/form-data">

  <input class="form-control" id="profile_image" type="file" name="profile_image" accept=".jpeg,.jpg,.png,"/>
 </form>

 Python code to save submitted image to res.partner:

 @http.route('/save/my/profile', type='http', auth="public", website=True)

    def save_image(self, **kw):
     datas = kw.get('profile_image').stream.getvalue()
     # store image in base64 format to image field of partner
     partner.sudo().write({'image': base64.encodestring(datas)})

Note: binary field for image should be defined with attachment=True

This image file will be stored inside the ir.attachment model (ir_attachment table).This table contains following values to establish the link to the original record:

    name: name of the binary field, e.g. image

    res_field: name of the binary field, e.g. image

    res_model: model containing the field, e.g. res.partner

    res_id: ID of the record the binary field belongs to

    type: 'binary'

    datas: virtual field with the contents of the binary field, which is actually stored on disk

Hope this will help you!

Thanks,

Avatar
Zrušiť

This error message show:

AttributeError: 'SpooledTemporaryFile' object has no attribute 'getvalue'

Related Posts Replies Zobrazenia Aktivita
2
jún 25
1445
1
feb 23
4285
3
nov 22
3965
2
jún 25
5501
0
okt 24
1887