I have Created my own Customer Attribute, it was a File attribute. While try to upload a file in that, it shows error like,
"<File Field Name>
" is not a valid file.
While checking in Media folder,
There was sub-folders created under customer folder.
But there was no files there.
Example:
If I upload a file like this, abcd.pdf
, then it creates folder like this,
/pub/media/customer/a/b/
Can any one help me to fix the issue.?
Here is my Attribute Creation code
$customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);
$customerEntity = $customerSetup->getEavConfig()->getEntityType('customer');
$attributeSetId = $customerEntity->getDefaultAttributeSetId();
/** @var $attributeSet AttributeSet */
$attributeSet = $this->attributeSetFactory->create();
$attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId);
$customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);
$customerEntity = $customerSetup->getEavConfig()->getEntityType('customer');
$attributeSetId = $customerEntity->getDefaultAttributeSetId();
/** @var $attributeSet AttributeSet */
$attributeSet = $this->attributeSetFactory->create();
$attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId);
$attributeList['my_file'] = [
'type' => 'varchar',
'label' => 'My File',
'input' => 'file',
'required' => false,
'visible' => true,
'user_defined' => true,
'sort_order' => 150,
'position' => 150,
'system' => 0,
'validate_rules' => serialize(['max_file_size' => 1048576, 'file_extensions' => 'pdf'])
];
foreach ($attributeList as $key => $value) {
$customerSetup->addAttribute(Customer::ENTITY, $key, $value);
//add attribute to attribute set
$attribute = $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, $key)
->addData([
'attribute_set_id' => $attributeSetId,
'attribute_group_id' => $attributeGroupId,
'used_in_forms' => ['customer_account_edit', 'checkout_register', 'adminhtml_customer']
]);
$attribute->save();
}