Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

save an image as a file in product_images_olbs

By
Wided
on 8/12/13, 10:33 AM 659 views

Hello,

I'm using product_images_olbs, it's working well. I'm trying to modify the code so I save the image uploaded with a different name in a file, but it doesn't work! Here's my code:

 def get_image(self, cr, uid, id):
    each = self.read(cr, uid, id, ['link', 'filename', 'image'])
    if each['link']:
        try:
            (filename, header) = urllib.urlretrieve(each['filename'])

            f = open(filename , 'rb')
            data=f.read()
            img = base64.encodestring(data)
            f.close()
            with open('test.jpg','wb') as f2:
               f2.write(data)

            f2.close()  


        except:
            img = ''
    else:
        img = each['image']

    return img

This code works when it's launched outside openerp!

Can someone help me figure out why the file test.jpg is not created?

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 8/12/13, 10:33 AM
Seen: 659 times
Last updated: 3/16/15, 8:10 AM