Search code examples
phppythonodooxml-rpc

Upload image to Odoo12 using XML-RPC


I am using xml-rpc to create new employee in Odoo, what I did so far is sending employee name and now I am trying to send and upload employee image to Odoo as well using xml-rpc. I have a php page that connected with Odoo.

  <?php>
     ........
     ........
     ........
     ........

     $id = $models->execute_kw($db, $uid, $password,
      'hr.employee','create', array(array('name'=>$_POST['name'], 'image'=>$_POST['image'])));

  ?>  

I do not know how to do it .I added this line 'image'=>$_POST['image'] but it does not work.


Solution

  • You can write as following :

    <?php>
         ........
         ........
         ........
         ........
    
         $b64image = base64_encode(file_get_contents('your image path'));
         $id = $models->execute_kw($db, $uid, $password,
          'hr.employee','create', array(array('name'=>$_POST['name'], 'image'=>$b64image)));
    
      ?>