تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2 الردود
23446 أدوات العرض

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

الصورة الرمزية
إهمال

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

أفضل إجابة

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>
الصورة الرمزية
إهمال

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.

أفضل إجابة

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

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
4
مارس 22
17259
2
ديسمبر 21
1787
0
أكتوبر 21
2897
3
نوفمبر 24
14040
0
يونيو 22
2376