Odoo - Python | File name too long, when processing images
Question: today I was making some code that will resize a few images that already been
uploaded. It is actually a def function and called when the button is pressed
on the Odoo web client.

Code:

    
    
    @api.multi
    def resize_image(self):
      for record in self:
        Image.open(self.foto1).resize((800, 600),Image.ANTIALIAS).save(self.foto1, quality=100)
    

Error:

    
    
      File "/opt/odoo/addons/asset/asset.py", line 209, in resize_image
        Image.open(self.foto1).resize((800, 600),Image.ANTIALIAS).save(self.foto1, quality=100)
    IOError: [Errno 36] File name too long: '/9j/4AAQSkZJRgABAQEASABIAAD/7QFKUGhvdG9zaG9wIDMuMAA4QklNBAQAAAAAAREcAVoAAxslRxwCAAACAAIcAhkAJkFGLVMgR
    

I can't give all the error file name because it's probably the byte itself...


Answer: 
    import cStringIO
    
    @api.multi
    def resize_image(self):
      for record in self:
        Image.open(cStringIO.StringIO(self.foto1.decode('base64'))).resize((800, 600),Image.ANTIALIAS).save(self.foto1, quality=100)
    

