Ir al contenido
Menú
Se marcó esta pregunta
2 Respuestas
23157 Vistas

How can I use urls instead of binary data for the product images? Or, if not possible, how to use the filesystem instead of the database for product images?

I know how to do it with attachments, but how does it work with product images?

Thanks for any proper answer...

Avatar
Descartar

did you meant to get an image from a url entered and show in binary field?

Mejor respuesta

if you meant to get an image from a given url: the python code and xml is as follows: python:

import base64#file encode
import urllib2 #file download from url

class image_url(osv.osv):
    _name="image.url"
    _columns={
               'image':fields.binary('Image',frequired=True),
               'web':fields.char('image url', help='Automatically sanitized HTML contents'),
                        }
    def onchange_image(self,cr,uid,ids,web,context=None):
        link=web
        photo = base64.encodestring(urllib2.urlopen(link).read())
        val={
             'image':photo,
             }
        return {'value': val}
 image_url()

xml view:

<record id="view_mrk_form" model="ir.ui.view">
            <field name="name">mark.marksheet.form</field>
            <field name="model">mark.marksheet</field>
            <field name="arch" type="xml">
            <form string="image">
                 <field name="image" widget="image" width="110" height="70" />
                 <field name="web" widget="url" on_change="onchange_image(web,context)"/>
            </form>
            </field>
</record>
Avatar
Descartar

Perfect..Thank You so much.. It helped a lot.

@Chandni, thank you for your detailed explanation. Do you have a github repository that I can fork this module from? I would like to include it as a dependency in an open-source theme module i'm building and would like to make sure I accredit you correctly.

Mejor respuesta

You have to check the link option and indicate your file location.

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
4
mar 22
16926
2
dic 21
1606
0
oct 21
2640
3
nov 24
13694
0
jun 22
2176