2

I've created one customer attribute with input type, Check below code for reference.

public function install(
    ModuleDataSetupInterface $setup,
    ModuleContextInterface $context
) {
    $customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);
    $setup->startSetup();
    $attributesInfo = [
        'upload_documents' => [
            'label' => 'Upload Document',
            'type' => 'varchar',
            'input' => 'image',
            'position' => 1000,
            'visible' => true,
            'required' => false,
            'system' => 0,
            'user_defined' => true,
            "source" => 'Magento\Eav\Model\Entity\Attribute\Source\Table',
            'position' => 1000,
            'is_used_in_grid' => true,
            'is_visible_in_grid' => true,
            'is_html_allowed_on_front' => true,
            'visible_on_front' => true
        ]
    ];
    $customerEntity = $customerSetup->getEavConfig()->getEntityType('customer');
    $attributeSetId = $customerEntity->getDefaultAttributeSetId();
    /** @var $attributeSet AttributeSet */
    $attributeSet = $this->attributeSetFactory->create();
    $attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId);
    foreach ($attributesInfo as $attributeCode => $attributeParams) {
        $customerSetup->addAttribute(Customer::ENTITY, $attributeCode, $attributeParams);
    }
    $magentoUsernameAttribute = $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, 'upload_documents');
    $magentoUsernameAttribute->addData([
        'attribute_set_id' => $attributeSetId,
        'attribute_group_id' => $attributeGroupId,
        'used_in_forms' => ['adminhtml_customer','customer_account_edit','adminhtml_checkout','adminhtml_customer_address','customer_address_edit','customer_register_address'],
    ]);
    $magentoUsernameAttribute->save();

        $setup->endSetup();

This is working fine, I can upload image from registration form. Its working with all image type but when I upload PDF it also working it display's PDF at backend.

Issue happens when I try to save customer which has PDF document its shows me error.

"Upload Document" is not a valid image format

Also after I can't upload PDF files from backend too.

Does anyone has what is I'm missing here ?? Any help would be appreciated.

0

By default magento does not allow PDF format on upload to make this an option you will need to create a basic extension and include

app/code/CustomVendor/CustomModule/etc/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Cms\Model\Wysiwyg\Images\Storage">
        <arguments>
            <argument name="resizeParameters" xsi:type="array">
                <item name="height" xsi:type="number">75</item>
                <item name="width" xsi:type="number">100</item>
            </argument>
            <argument name="extensions" xsi:type="array">
                <item name="allowed" xsi:type="array">
                    <item name="jpg" xsi:type="number">1</item>
                    <item name="jpeg" xsi:type="number">1</item>
                    <item name="png" xsi:type="number">1</item>
                    <item name="gif" xsi:type="number">1</item>
                    <item name="pdf" xsi:type="number">1</item>
                </item>
                <item name="image_allowed" xsi:type="array">
                    <item name="jpg" xsi:type="number">1</item>
                    <item name="jpeg" xsi:type="number">1</item>
                    <item name="png" xsi:type="number">1</item>
                    <item name="gif" xsi:type="number">1</item>
                </item>
                <item name="media_allowed" xsi:type="array">
                    <item name="flv" xsi:type="number">1</item>
                    <item name="swf" xsi:type="number">1</item>
                    <item name="avi" xsi:type="number">1</item>
                    <item name="mov" xsi:type="number">1</item>
                    <item name="rm" xsi:type="number">1</item>
                    <item name="wmv" xsi:type="number">1</item>
                    <item name="pdf" xsi:type="number">1</item>
                </item>
            </argument>
            <argument name="dirs" xsi:type="array">
                <item name="exclude" xsi:type="string"/>
                <item name="include" xsi:type="string"/>
            </argument>
        </arguments>
    </type>
</config>
  • Thanks for you response but its for WYSIWYG editor, I need it for for customer attribute. – Vivek Apr 15 at 5:27
  • Yeah the Wysiwygs use the same functionality and the same paramerters for uploads so if you put this in place it should work i have tested this on a number of methods – Dava Gordon Apr 15 at 9:18

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.