0

I added image attribute in customer create account, edit account in Setup/InstallData.php as following:

public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
    {

        $installer = $setup;
        $installer->startSetup();

        $customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);
        $entityTypeId = $customerSetup->getEntityTypeId(\Magento\Customer\Model\Customer::ENTITY);
        $customerSetup->removeAttribute(\Magento\Customer\Model\Customer::ENTITY, "avatar");

        $customerSetup->addAttribute(\Magento\Customer\Model\Customer::ENTITY, "avatar",  array(
            "type"     => "varchar",
            "backend"  => "",
            "label"    => "Avatar",
            "input"    => "image",
            "source"   => "",
            "visible"  => true,
            "required" => true,
            "default" => "",
            "frontend" => "",
            "unique"     => false,
            "note"       => ""

        ));

        $promotion_code   = $customerSetup->getAttribute(\Magento\Customer\Model\Customer::ENTITY, "avatar");

        $promotion_code = $customerSetup->getEavConfig()->getAttribute(\Magento\Customer\Model\Customer::ENTITY, 'avatar');
        $used_in_forms[]="adminhtml_customer";
        $used_in_forms[]="checkout_register";
        $used_in_forms[]="customer_account_create";
        $used_in_forms[]="customer_account_edit";
        $used_in_forms[]="adminhtml_checkout";
        $promotion_code->setData("used_in_forms", $used_in_forms)
            ->setData("is_used_for_customer_segment", true)
            ->setData("is_system", 0)
            ->setData("is_user_defined", 1)
            ->setData("is_visible", 1)
            ->setData("sort_order", 100);

        $promotion_code->save();



        $installer->endSetup();
    }

The problem is I cant do sign up via REST API, I am using this API :

POST http://domain.com/index.php/rest/V1/customers

Body :

  {
     "customer": {
         "email": "abc@gmail.com",
         "firstname": "Abc",
         "lastname": "Xyz" ,
         "custom_attributes": [
          {
            "attribute_code": "avatar",
            "value": ""  //encoded base_64 image
          }
        ]

     },

     "password": "Abc@123456"
  }

I tries to put Image in encoding base64 image, but I always get this error:

{
    "message": "The image content must be valid base64 encoded data."
}

How can I solve this?

In general are the body parameters correct, If not how can I post correct body?

0

You can try below json format, it worked for me:-

@PY Yick suggestion provided the hint:-

{
 "customer": {
     "email": "abc1@gmail.com",
     "firstname": "Abc",
     "lastname": "Xyz" ,
     "custom_attributes": [
      {
        "attribute_code": "twilio_image",
        "value": {
            "base64EncodedData": "iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAWtJREFUeNpi/P//P8NgBkwMgxyMOnDUgTDAyMhIDNYF4vNA/B+IDwCxHLoakgEoFxODiQRXQUYi4e3k2gfDjMRajsP3zED8F8pmA+JvUDEYeArEMugOpFcanA/Ef6A0CPwC4uNoag5SnAjJjGI2tKhkg4rLAfFGIH4IxEuBWIjSKKYkDfZCHddLiwChVhokK8YGohwEZYy3aBmEKmDEhOCgreomo+VmZHxsMEQxIc2MAx3FO/DI3RxMmQTZkI9ALDCaSUYdOOrAIeRAPzQ+PxCHUM2FFDb5paGNBPRa5C20bUhxc4sSB4JaLnvxVHWHsbVu6OnACjyOg+HqgXKgGRD/JMKBoD6LDb0dyAPE94hwHAw/hGYcujlwEQmOg+EV9HJgLBmOg+FMWjsQVKR8psCBoDSrQqoDSSmoG6Hpj1wA6ju30LI9+BBX4UsC+Ai0T4BWVd1EIL5PgeO+APECmoXgaGtm1IE0AgABBgAJAICuV8dAUAAAAABJRU5ErkJggg==",
            "type": "image/png",
            "name": "new_image.png"
        }
      }
    ]

 },

 "password": "Abc@123456"

}

  • Thank you very much, How can I encode image? if you are using specific tool, provide me it is working only for your image and when encode any image I got error ''"message": "The image MIME type is not valid or not supported." , Another question Is this solution working for edit customer ? sorry for the more questions. – Jsparo30 Aug 2 '17 at 6:33
  • @base64_encode(file_get_contents('new_image.png')) use this you can check in framework\Api\ImageContentValidatorTest.php at line 114, magento is using the same and it worked for me as well. – arushi Aug 2 '17 at 7:02
  • Ok, It is working fine. what about edit customer? Thanks.. – Jsparo30 Aug 2 '17 at 8:28
  • means, you want to add image for customer as well – arushi Aug 2 '17 at 8:31
  • I mean it is working fine when sign up, I am asking How can I edit customer with image attribute? – Jsparo30 Aug 2 '17 at 9:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.