Help

4

How to use urls as product images?

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...

1 Comment
Avatar
Discard
Avatar
dianne jose
-

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

2 Answers
8
Avatar
dianne jose
Best Answer

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>
2 Comments
Avatar
Discard
Avatar
Chandni Machchhar
-

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

Avatar
Luke Branch
-

@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.

1
Avatar
Wided
Best Answer

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

Avatar
Discard