Magento 2: Getting error Unsupported image format. File: /var/www/mysite/pub/media//Meeting_notes_2__1.docxMagento 2: can't access pub/media filesMagento 2. How to upload images to pub/mediaHow to read file to string from pub/media directory?magento 2.1.3 pub/media/styles.css file not existedMagento 2: Upload PDF gives Unsupported image format. ErrorMagento 2 - Use of the Media Image Uploadererror magento 2: FilesystemIterator::__construct(/var/www/html/pub/static/_requirejs/frontend/Magento): failed to open dir: Permission deniedMagento 2: format var invoice.created_atDirectory “/var/www/magento2/pub/static/frontend/<Vendor>” cannot be created Warning!mkdir(): Protocol errorMagento 2.2.5 - Unsupported image format on product detail page

Why am I getting an electric shock from the water in my hot tub?

Displace Mesh along Curve on single axis

Is there a connection between representation theory and PDEs?

I agreed to cancel a long-planned vacation (with travel costs) due to project deadlines, but now the timeline has all changed again

Is it theoretically possible to hack printer using scanner tray?

Is my background sufficient to start Quantum Computing

GFCI versus circuit breaker

How come having a Deathly Hallow is not a big deal?

Does friction always oppose motion?

What is the point of using the kunai?

Why are symbols not written in words?

What prevents a US state from colonizing a smaller state?

When does it become illegal to exchange bitcoin for cash?

*p++->str : Understanding evaluation of ->

Why is my 401k manager recommending me to save more?

What type of education should I select in this form?

Is this house-rule removing the increased effect of cantrips at higher character levels balanced?

Did the Shuttle payload bay have illumination?

Other homotopy invariants?

Is it OK to throw pebbles and stones in streams, waterfalls, ponds, etc.?

Is it OK to say "The situation is pregnant with a crisis"?

Replacing 5 gang light switches that have 3 of them daisy chained together

"Best practices" for formulating MIPs

Installed software from source, how to say yum not to install it from package?



Magento 2: Getting error Unsupported image format. File: /var/www/mysite/pub/media//Meeting_notes_2__1.docx


Magento 2: can't access pub/media filesMagento 2. How to upload images to pub/mediaHow to read file to string from pub/media directory?magento 2.1.3 pub/media/styles.css file not existedMagento 2: Upload PDF gives Unsupported image format. ErrorMagento 2 - Use of the Media Image Uploadererror magento 2: FilesystemIterator::__construct(/var/www/html/pub/static/_requirejs/frontend/Magento): failed to open dir: Permission deniedMagento 2: format var invoice.created_atDirectory “/var/www/magento2/pub/static/frontend/<Vendor>” cannot be created Warning!mkdir(): Protocol errorMagento 2.2.5 - Unsupported image format on product detail page













4















I am getting an error in admin editor:




Unsupported image format. File:
/var/www/clients/mysite/pub/media//Meeting_notes_2__1.docx




My Code is



<type name="MagentoCmsModelWysiwygImagesStorage">
<arguments>
<argument name="extensions" xsi:type="array">
<item name="allowed" xsi:type="array">
<item name="pdf" xsi:type="number">1</item>
<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="docx" 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 name="docx" 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="docx" xsi:type="number">1</item>
</item>
</argument>
</arguments>
</type>
<preference for="MagentoCmsModelWysiwygImagesStorage" type="VendorModuleNameModelCmsWysiwygImagesStorage" />









share|improve this question
























  • You get this error because of you have defined Type for Image (MagentoCmsModelWysiwygImagesStorage) and pass argument item for docx You can see in magento core file/vendor/magento/module-cms/etc/di.xml there is no such a file type extension for you given Type.

    – Chirag Patel
    Jun 24 at 11:36











  • Using the above code what do you want to achieve? what do you want to do?

    – Chirag Patel
    Jun 24 at 11:37











  • @chirag I have updated my code. Can you please check and suggest the solution for this

    – Shiwani
    Jun 24 at 12:40











  • Why you are pass <item name="docx" xsi:type="number">1</item> what do you want? do you want file upload functionality in admin or frontend form?

    – Chirag Patel
    Jun 24 at 13:13











  • @ChiragPatel I need upload funtionality for Wysiwyg editor in magento2 admin.

    – Shiwani
    Jun 25 at 4:30















4















I am getting an error in admin editor:




Unsupported image format. File:
/var/www/clients/mysite/pub/media//Meeting_notes_2__1.docx




My Code is



<type name="MagentoCmsModelWysiwygImagesStorage">
<arguments>
<argument name="extensions" xsi:type="array">
<item name="allowed" xsi:type="array">
<item name="pdf" xsi:type="number">1</item>
<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="docx" 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 name="docx" 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="docx" xsi:type="number">1</item>
</item>
</argument>
</arguments>
</type>
<preference for="MagentoCmsModelWysiwygImagesStorage" type="VendorModuleNameModelCmsWysiwygImagesStorage" />









share|improve this question
























  • You get this error because of you have defined Type for Image (MagentoCmsModelWysiwygImagesStorage) and pass argument item for docx You can see in magento core file/vendor/magento/module-cms/etc/di.xml there is no such a file type extension for you given Type.

    – Chirag Patel
    Jun 24 at 11:36











  • Using the above code what do you want to achieve? what do you want to do?

    – Chirag Patel
    Jun 24 at 11:37











  • @chirag I have updated my code. Can you please check and suggest the solution for this

    – Shiwani
    Jun 24 at 12:40











  • Why you are pass <item name="docx" xsi:type="number">1</item> what do you want? do you want file upload functionality in admin or frontend form?

    – Chirag Patel
    Jun 24 at 13:13











  • @ChiragPatel I need upload funtionality for Wysiwyg editor in magento2 admin.

    – Shiwani
    Jun 25 at 4:30













4












4








4


1






I am getting an error in admin editor:




Unsupported image format. File:
/var/www/clients/mysite/pub/media//Meeting_notes_2__1.docx




My Code is



<type name="MagentoCmsModelWysiwygImagesStorage">
<arguments>
<argument name="extensions" xsi:type="array">
<item name="allowed" xsi:type="array">
<item name="pdf" xsi:type="number">1</item>
<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="docx" 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 name="docx" 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="docx" xsi:type="number">1</item>
</item>
</argument>
</arguments>
</type>
<preference for="MagentoCmsModelWysiwygImagesStorage" type="VendorModuleNameModelCmsWysiwygImagesStorage" />









share|improve this question
















I am getting an error in admin editor:




Unsupported image format. File:
/var/www/clients/mysite/pub/media//Meeting_notes_2__1.docx




My Code is



<type name="MagentoCmsModelWysiwygImagesStorage">
<arguments>
<argument name="extensions" xsi:type="array">
<item name="allowed" xsi:type="array">
<item name="pdf" xsi:type="number">1</item>
<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="docx" 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 name="docx" 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="docx" xsi:type="number">1</item>
</item>
</argument>
</arguments>
</type>
<preference for="MagentoCmsModelWysiwygImagesStorage" type="VendorModuleNameModelCmsWysiwygImagesStorage" />






magento2 image-upload






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jun 24 at 12:38







Shiwani

















asked Jun 24 at 10:52









ShiwaniShiwani

34211 bronze badges




34211 bronze badges












  • You get this error because of you have defined Type for Image (MagentoCmsModelWysiwygImagesStorage) and pass argument item for docx You can see in magento core file/vendor/magento/module-cms/etc/di.xml there is no such a file type extension for you given Type.

    – Chirag Patel
    Jun 24 at 11:36











  • Using the above code what do you want to achieve? what do you want to do?

    – Chirag Patel
    Jun 24 at 11:37











  • @chirag I have updated my code. Can you please check and suggest the solution for this

    – Shiwani
    Jun 24 at 12:40











  • Why you are pass <item name="docx" xsi:type="number">1</item> what do you want? do you want file upload functionality in admin or frontend form?

    – Chirag Patel
    Jun 24 at 13:13











  • @ChiragPatel I need upload funtionality for Wysiwyg editor in magento2 admin.

    – Shiwani
    Jun 25 at 4:30

















  • You get this error because of you have defined Type for Image (MagentoCmsModelWysiwygImagesStorage) and pass argument item for docx You can see in magento core file/vendor/magento/module-cms/etc/di.xml there is no such a file type extension for you given Type.

    – Chirag Patel
    Jun 24 at 11:36











  • Using the above code what do you want to achieve? what do you want to do?

    – Chirag Patel
    Jun 24 at 11:37











  • @chirag I have updated my code. Can you please check and suggest the solution for this

    – Shiwani
    Jun 24 at 12:40











  • Why you are pass <item name="docx" xsi:type="number">1</item> what do you want? do you want file upload functionality in admin or frontend form?

    – Chirag Patel
    Jun 24 at 13:13











  • @ChiragPatel I need upload funtionality for Wysiwyg editor in magento2 admin.

    – Shiwani
    Jun 25 at 4:30
















You get this error because of you have defined Type for Image (MagentoCmsModelWysiwygImagesStorage) and pass argument item for docx You can see in magento core file/vendor/magento/module-cms/etc/di.xml there is no such a file type extension for you given Type.

– Chirag Patel
Jun 24 at 11:36





You get this error because of you have defined Type for Image (MagentoCmsModelWysiwygImagesStorage) and pass argument item for docx You can see in magento core file/vendor/magento/module-cms/etc/di.xml there is no such a file type extension for you given Type.

– Chirag Patel
Jun 24 at 11:36













Using the above code what do you want to achieve? what do you want to do?

– Chirag Patel
Jun 24 at 11:37





Using the above code what do you want to achieve? what do you want to do?

– Chirag Patel
Jun 24 at 11:37













@chirag I have updated my code. Can you please check and suggest the solution for this

– Shiwani
Jun 24 at 12:40





@chirag I have updated my code. Can you please check and suggest the solution for this

– Shiwani
Jun 24 at 12:40













Why you are pass <item name="docx" xsi:type="number">1</item> what do you want? do you want file upload functionality in admin or frontend form?

– Chirag Patel
Jun 24 at 13:13





Why you are pass <item name="docx" xsi:type="number">1</item> what do you want? do you want file upload functionality in admin or frontend form?

– Chirag Patel
Jun 24 at 13:13













@ChiragPatel I need upload funtionality for Wysiwyg editor in magento2 admin.

– Shiwani
Jun 25 at 4:30





@ChiragPatel I need upload funtionality for Wysiwyg editor in magento2 admin.

– Shiwani
Jun 25 at 4:30










2 Answers
2






active

oldest

votes


















1














There is no need to pass docx file extension to <item name="image_allowed" xsi:type="array"> and <item name="media_allowed" xsi:type="array"> try with below way it's working for me in Magento 2.3.1.




app/code/[Company]/[Module]/etc/di.xml




Add below code.



<type name="MagentoCmsModelWysiwygImagesStorage">
<arguments>
<argument name="extensions" xsi:type="array">
<item name="allowed" xsi:type="array">
<item name="docx" xsi:type="number">1</item>
<item name="pdf" xsi:type="number">1</item>
</item>
</argument>
</arguments>
</type>
<preference for="MagentoCmsModelWysiwygImagesStorage" type="[Company][Module]ModelCmsWysiwygImagesStorage" />


create Storage.php file at below path.




app/code/[Company]/[Module]/Model/Cms/Wysiwyg/Images/Storage.php




 <?php

namespace [Company][Module]ModelCmsWysiwygImages;

class Storage extends MagentoCmsModelWysiwygImagesStorage

public function uploadFile($targetPath, $type = null)

/** @var MagentoMediaStorageModelFileUploader $uploader */
$uploader = $this->_uploaderFactory->create(['fileId' => 'image']);
$allowed = $this->getAllowedExtensions($type);
if ($allowed)
$uploader->setAllowedExtensions($allowed);

$uploader->setAllowRenameFiles(true);
$uploader->setFilesDispersion(false);
$result = $uploader->save($targetPath);

if (!$result)
throw new MagentoFrameworkExceptionLocalizedException(__('We can't upload the file right now.'));


// Change Start
if (strtolower($uploader->getFileExtension()) !== 'docx' && strtolower($uploader->getFileExtension()) !== 'pdf')
// Create Thumbnail
$this->resizeFile($targetPath . '/' . $uploader->getUploadedFileName(), true);


$result['cookie'] = [
'name' => $this->getSession()->getName(),
'value' => $this->getSession()->getSessionId(),
'lifetime' => $this->getSession()->getCookieLifetime(),
'path' => $this->getSession()->getCookiePath(),
'domain' => $this->getSession()->getCookieDomain(),
];

return $result;





Run php bin/magento cache:clean




Then Go to Admin > Content > Page > Edit or Add new page Inside content click on insert image and upload docx file



I hope it helps!






share|improve this answer

























  • I did already same for Pdf. This is working for pdf file but need to enable also for doc and docx file in editor

    – Shiwani
    Jun 25 at 5:08











  • Just copy and paste my code, I have just test now it's working. And let me know.

    – Chirag Patel
    Jun 25 at 5:11












  • Okay let me check and update you

    – Shiwani
    Jun 25 at 5:17






  • 1





    Your code is working fine. you need to update one thing. If you are adding this line ---- <item name="pdf" xsi:type="number">1</item>-- for pdf then you need to add pdf in this condition if (strtolower($uploader->getFileExtension()) !== 'pdf') .. Please update your comment. ------------------>Also add for docx file with this way <item name="docx" xsi:type="number">1</item> and add condition like this if (strtolower($uploader->getFileExtension()) !== 'docx' && strtolower($uploader->getFileExtension()) !== 'pdf')

    – Shiwani
    Jun 25 at 6:02












  • Ohhh, sorry it is a typo mistake. I have updated my answer. see and you can accept the answer so it will usefull for other users :) Thanks.

    – Chirag Patel
    Jun 25 at 6:14


















2














Please Look at here,



Please change this file




project/vendor/magento/module-cms/etc/di.xml




Add any extension you want to add <item name="docx" xsi:type="number">1</item>



<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="docx" 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 name="docx" 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="docx" xsi:type="number">1</item>
</item>







share|improve this answer

























  • This is not working.. already tried it

    – Shiwani
    Jun 24 at 11:00












  • Check my updated code.

    – Magento_Bhurio
    Jun 24 at 11:01











  • what you have updated in this code?

    – Shiwani
    Jun 24 at 11:03











  • In second add <item name="image_allowed" xsi:type="array"> add this line :- <item name="docx" xsi:type="number">1</item>

    – Magento_Bhurio
    Jun 24 at 11:03












  • This is adding doc and docx file but showing error. I am not able to figure out how to fix this.

    – Shiwani
    Jun 24 at 11:14













Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f279391%2fmagento-2-getting-error-unsupported-image-format-file-var-www-mysite-pub-med%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














There is no need to pass docx file extension to <item name="image_allowed" xsi:type="array"> and <item name="media_allowed" xsi:type="array"> try with below way it's working for me in Magento 2.3.1.




app/code/[Company]/[Module]/etc/di.xml




Add below code.



<type name="MagentoCmsModelWysiwygImagesStorage">
<arguments>
<argument name="extensions" xsi:type="array">
<item name="allowed" xsi:type="array">
<item name="docx" xsi:type="number">1</item>
<item name="pdf" xsi:type="number">1</item>
</item>
</argument>
</arguments>
</type>
<preference for="MagentoCmsModelWysiwygImagesStorage" type="[Company][Module]ModelCmsWysiwygImagesStorage" />


create Storage.php file at below path.




app/code/[Company]/[Module]/Model/Cms/Wysiwyg/Images/Storage.php




 <?php

namespace [Company][Module]ModelCmsWysiwygImages;

class Storage extends MagentoCmsModelWysiwygImagesStorage

public function uploadFile($targetPath, $type = null)

/** @var MagentoMediaStorageModelFileUploader $uploader */
$uploader = $this->_uploaderFactory->create(['fileId' => 'image']);
$allowed = $this->getAllowedExtensions($type);
if ($allowed)
$uploader->setAllowedExtensions($allowed);

$uploader->setAllowRenameFiles(true);
$uploader->setFilesDispersion(false);
$result = $uploader->save($targetPath);

if (!$result)
throw new MagentoFrameworkExceptionLocalizedException(__('We can't upload the file right now.'));


// Change Start
if (strtolower($uploader->getFileExtension()) !== 'docx' && strtolower($uploader->getFileExtension()) !== 'pdf')
// Create Thumbnail
$this->resizeFile($targetPath . '/' . $uploader->getUploadedFileName(), true);


$result['cookie'] = [
'name' => $this->getSession()->getName(),
'value' => $this->getSession()->getSessionId(),
'lifetime' => $this->getSession()->getCookieLifetime(),
'path' => $this->getSession()->getCookiePath(),
'domain' => $this->getSession()->getCookieDomain(),
];

return $result;





Run php bin/magento cache:clean




Then Go to Admin > Content > Page > Edit or Add new page Inside content click on insert image and upload docx file



I hope it helps!






share|improve this answer

























  • I did already same for Pdf. This is working for pdf file but need to enable also for doc and docx file in editor

    – Shiwani
    Jun 25 at 5:08











  • Just copy and paste my code, I have just test now it's working. And let me know.

    – Chirag Patel
    Jun 25 at 5:11












  • Okay let me check and update you

    – Shiwani
    Jun 25 at 5:17






  • 1





    Your code is working fine. you need to update one thing. If you are adding this line ---- <item name="pdf" xsi:type="number">1</item>-- for pdf then you need to add pdf in this condition if (strtolower($uploader->getFileExtension()) !== 'pdf') .. Please update your comment. ------------------>Also add for docx file with this way <item name="docx" xsi:type="number">1</item> and add condition like this if (strtolower($uploader->getFileExtension()) !== 'docx' && strtolower($uploader->getFileExtension()) !== 'pdf')

    – Shiwani
    Jun 25 at 6:02












  • Ohhh, sorry it is a typo mistake. I have updated my answer. see and you can accept the answer so it will usefull for other users :) Thanks.

    – Chirag Patel
    Jun 25 at 6:14















1














There is no need to pass docx file extension to <item name="image_allowed" xsi:type="array"> and <item name="media_allowed" xsi:type="array"> try with below way it's working for me in Magento 2.3.1.




app/code/[Company]/[Module]/etc/di.xml




Add below code.



<type name="MagentoCmsModelWysiwygImagesStorage">
<arguments>
<argument name="extensions" xsi:type="array">
<item name="allowed" xsi:type="array">
<item name="docx" xsi:type="number">1</item>
<item name="pdf" xsi:type="number">1</item>
</item>
</argument>
</arguments>
</type>
<preference for="MagentoCmsModelWysiwygImagesStorage" type="[Company][Module]ModelCmsWysiwygImagesStorage" />


create Storage.php file at below path.




app/code/[Company]/[Module]/Model/Cms/Wysiwyg/Images/Storage.php




 <?php

namespace [Company][Module]ModelCmsWysiwygImages;

class Storage extends MagentoCmsModelWysiwygImagesStorage

public function uploadFile($targetPath, $type = null)

/** @var MagentoMediaStorageModelFileUploader $uploader */
$uploader = $this->_uploaderFactory->create(['fileId' => 'image']);
$allowed = $this->getAllowedExtensions($type);
if ($allowed)
$uploader->setAllowedExtensions($allowed);

$uploader->setAllowRenameFiles(true);
$uploader->setFilesDispersion(false);
$result = $uploader->save($targetPath);

if (!$result)
throw new MagentoFrameworkExceptionLocalizedException(__('We can't upload the file right now.'));


// Change Start
if (strtolower($uploader->getFileExtension()) !== 'docx' && strtolower($uploader->getFileExtension()) !== 'pdf')
// Create Thumbnail
$this->resizeFile($targetPath . '/' . $uploader->getUploadedFileName(), true);


$result['cookie'] = [
'name' => $this->getSession()->getName(),
'value' => $this->getSession()->getSessionId(),
'lifetime' => $this->getSession()->getCookieLifetime(),
'path' => $this->getSession()->getCookiePath(),
'domain' => $this->getSession()->getCookieDomain(),
];

return $result;





Run php bin/magento cache:clean




Then Go to Admin > Content > Page > Edit or Add new page Inside content click on insert image and upload docx file



I hope it helps!






share|improve this answer

























  • I did already same for Pdf. This is working for pdf file but need to enable also for doc and docx file in editor

    – Shiwani
    Jun 25 at 5:08











  • Just copy and paste my code, I have just test now it's working. And let me know.

    – Chirag Patel
    Jun 25 at 5:11












  • Okay let me check and update you

    – Shiwani
    Jun 25 at 5:17






  • 1





    Your code is working fine. you need to update one thing. If you are adding this line ---- <item name="pdf" xsi:type="number">1</item>-- for pdf then you need to add pdf in this condition if (strtolower($uploader->getFileExtension()) !== 'pdf') .. Please update your comment. ------------------>Also add for docx file with this way <item name="docx" xsi:type="number">1</item> and add condition like this if (strtolower($uploader->getFileExtension()) !== 'docx' && strtolower($uploader->getFileExtension()) !== 'pdf')

    – Shiwani
    Jun 25 at 6:02












  • Ohhh, sorry it is a typo mistake. I have updated my answer. see and you can accept the answer so it will usefull for other users :) Thanks.

    – Chirag Patel
    Jun 25 at 6:14













1












1








1







There is no need to pass docx file extension to <item name="image_allowed" xsi:type="array"> and <item name="media_allowed" xsi:type="array"> try with below way it's working for me in Magento 2.3.1.




app/code/[Company]/[Module]/etc/di.xml




Add below code.



<type name="MagentoCmsModelWysiwygImagesStorage">
<arguments>
<argument name="extensions" xsi:type="array">
<item name="allowed" xsi:type="array">
<item name="docx" xsi:type="number">1</item>
<item name="pdf" xsi:type="number">1</item>
</item>
</argument>
</arguments>
</type>
<preference for="MagentoCmsModelWysiwygImagesStorage" type="[Company][Module]ModelCmsWysiwygImagesStorage" />


create Storage.php file at below path.




app/code/[Company]/[Module]/Model/Cms/Wysiwyg/Images/Storage.php




 <?php

namespace [Company][Module]ModelCmsWysiwygImages;

class Storage extends MagentoCmsModelWysiwygImagesStorage

public function uploadFile($targetPath, $type = null)

/** @var MagentoMediaStorageModelFileUploader $uploader */
$uploader = $this->_uploaderFactory->create(['fileId' => 'image']);
$allowed = $this->getAllowedExtensions($type);
if ($allowed)
$uploader->setAllowedExtensions($allowed);

$uploader->setAllowRenameFiles(true);
$uploader->setFilesDispersion(false);
$result = $uploader->save($targetPath);

if (!$result)
throw new MagentoFrameworkExceptionLocalizedException(__('We can't upload the file right now.'));


// Change Start
if (strtolower($uploader->getFileExtension()) !== 'docx' && strtolower($uploader->getFileExtension()) !== 'pdf')
// Create Thumbnail
$this->resizeFile($targetPath . '/' . $uploader->getUploadedFileName(), true);


$result['cookie'] = [
'name' => $this->getSession()->getName(),
'value' => $this->getSession()->getSessionId(),
'lifetime' => $this->getSession()->getCookieLifetime(),
'path' => $this->getSession()->getCookiePath(),
'domain' => $this->getSession()->getCookieDomain(),
];

return $result;





Run php bin/magento cache:clean




Then Go to Admin > Content > Page > Edit or Add new page Inside content click on insert image and upload docx file



I hope it helps!






share|improve this answer















There is no need to pass docx file extension to <item name="image_allowed" xsi:type="array"> and <item name="media_allowed" xsi:type="array"> try with below way it's working for me in Magento 2.3.1.




app/code/[Company]/[Module]/etc/di.xml




Add below code.



<type name="MagentoCmsModelWysiwygImagesStorage">
<arguments>
<argument name="extensions" xsi:type="array">
<item name="allowed" xsi:type="array">
<item name="docx" xsi:type="number">1</item>
<item name="pdf" xsi:type="number">1</item>
</item>
</argument>
</arguments>
</type>
<preference for="MagentoCmsModelWysiwygImagesStorage" type="[Company][Module]ModelCmsWysiwygImagesStorage" />


create Storage.php file at below path.




app/code/[Company]/[Module]/Model/Cms/Wysiwyg/Images/Storage.php




 <?php

namespace [Company][Module]ModelCmsWysiwygImages;

class Storage extends MagentoCmsModelWysiwygImagesStorage

public function uploadFile($targetPath, $type = null)

/** @var MagentoMediaStorageModelFileUploader $uploader */
$uploader = $this->_uploaderFactory->create(['fileId' => 'image']);
$allowed = $this->getAllowedExtensions($type);
if ($allowed)
$uploader->setAllowedExtensions($allowed);

$uploader->setAllowRenameFiles(true);
$uploader->setFilesDispersion(false);
$result = $uploader->save($targetPath);

if (!$result)
throw new MagentoFrameworkExceptionLocalizedException(__('We can't upload the file right now.'));


// Change Start
if (strtolower($uploader->getFileExtension()) !== 'docx' && strtolower($uploader->getFileExtension()) !== 'pdf')
// Create Thumbnail
$this->resizeFile($targetPath . '/' . $uploader->getUploadedFileName(), true);


$result['cookie'] = [
'name' => $this->getSession()->getName(),
'value' => $this->getSession()->getSessionId(),
'lifetime' => $this->getSession()->getCookieLifetime(),
'path' => $this->getSession()->getCookiePath(),
'domain' => $this->getSession()->getCookieDomain(),
];

return $result;





Run php bin/magento cache:clean




Then Go to Admin > Content > Page > Edit or Add new page Inside content click on insert image and upload docx file



I hope it helps!







share|improve this answer














share|improve this answer



share|improve this answer








edited Jun 25 at 6:19

























answered Jun 25 at 5:04









Chirag PatelChirag Patel

3,6366 silver badges28 bronze badges




3,6366 silver badges28 bronze badges












  • I did already same for Pdf. This is working for pdf file but need to enable also for doc and docx file in editor

    – Shiwani
    Jun 25 at 5:08











  • Just copy and paste my code, I have just test now it's working. And let me know.

    – Chirag Patel
    Jun 25 at 5:11












  • Okay let me check and update you

    – Shiwani
    Jun 25 at 5:17






  • 1





    Your code is working fine. you need to update one thing. If you are adding this line ---- <item name="pdf" xsi:type="number">1</item>-- for pdf then you need to add pdf in this condition if (strtolower($uploader->getFileExtension()) !== 'pdf') .. Please update your comment. ------------------>Also add for docx file with this way <item name="docx" xsi:type="number">1</item> and add condition like this if (strtolower($uploader->getFileExtension()) !== 'docx' && strtolower($uploader->getFileExtension()) !== 'pdf')

    – Shiwani
    Jun 25 at 6:02












  • Ohhh, sorry it is a typo mistake. I have updated my answer. see and you can accept the answer so it will usefull for other users :) Thanks.

    – Chirag Patel
    Jun 25 at 6:14

















  • I did already same for Pdf. This is working for pdf file but need to enable also for doc and docx file in editor

    – Shiwani
    Jun 25 at 5:08











  • Just copy and paste my code, I have just test now it's working. And let me know.

    – Chirag Patel
    Jun 25 at 5:11












  • Okay let me check and update you

    – Shiwani
    Jun 25 at 5:17






  • 1





    Your code is working fine. you need to update one thing. If you are adding this line ---- <item name="pdf" xsi:type="number">1</item>-- for pdf then you need to add pdf in this condition if (strtolower($uploader->getFileExtension()) !== 'pdf') .. Please update your comment. ------------------>Also add for docx file with this way <item name="docx" xsi:type="number">1</item> and add condition like this if (strtolower($uploader->getFileExtension()) !== 'docx' && strtolower($uploader->getFileExtension()) !== 'pdf')

    – Shiwani
    Jun 25 at 6:02












  • Ohhh, sorry it is a typo mistake. I have updated my answer. see and you can accept the answer so it will usefull for other users :) Thanks.

    – Chirag Patel
    Jun 25 at 6:14
















I did already same for Pdf. This is working for pdf file but need to enable also for doc and docx file in editor

– Shiwani
Jun 25 at 5:08





I did already same for Pdf. This is working for pdf file but need to enable also for doc and docx file in editor

– Shiwani
Jun 25 at 5:08













Just copy and paste my code, I have just test now it's working. And let me know.

– Chirag Patel
Jun 25 at 5:11






Just copy and paste my code, I have just test now it's working. And let me know.

– Chirag Patel
Jun 25 at 5:11














Okay let me check and update you

– Shiwani
Jun 25 at 5:17





Okay let me check and update you

– Shiwani
Jun 25 at 5:17




1




1





Your code is working fine. you need to update one thing. If you are adding this line ---- <item name="pdf" xsi:type="number">1</item>-- for pdf then you need to add pdf in this condition if (strtolower($uploader->getFileExtension()) !== 'pdf') .. Please update your comment. ------------------>Also add for docx file with this way <item name="docx" xsi:type="number">1</item> and add condition like this if (strtolower($uploader->getFileExtension()) !== 'docx' && strtolower($uploader->getFileExtension()) !== 'pdf')

– Shiwani
Jun 25 at 6:02






Your code is working fine. you need to update one thing. If you are adding this line ---- <item name="pdf" xsi:type="number">1</item>-- for pdf then you need to add pdf in this condition if (strtolower($uploader->getFileExtension()) !== 'pdf') .. Please update your comment. ------------------>Also add for docx file with this way <item name="docx" xsi:type="number">1</item> and add condition like this if (strtolower($uploader->getFileExtension()) !== 'docx' && strtolower($uploader->getFileExtension()) !== 'pdf')

– Shiwani
Jun 25 at 6:02














Ohhh, sorry it is a typo mistake. I have updated my answer. see and you can accept the answer so it will usefull for other users :) Thanks.

– Chirag Patel
Jun 25 at 6:14





Ohhh, sorry it is a typo mistake. I have updated my answer. see and you can accept the answer so it will usefull for other users :) Thanks.

– Chirag Patel
Jun 25 at 6:14











2














Please Look at here,



Please change this file




project/vendor/magento/module-cms/etc/di.xml




Add any extension you want to add <item name="docx" xsi:type="number">1</item>



<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="docx" 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 name="docx" 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="docx" xsi:type="number">1</item>
</item>







share|improve this answer

























  • This is not working.. already tried it

    – Shiwani
    Jun 24 at 11:00












  • Check my updated code.

    – Magento_Bhurio
    Jun 24 at 11:01











  • what you have updated in this code?

    – Shiwani
    Jun 24 at 11:03











  • In second add <item name="image_allowed" xsi:type="array"> add this line :- <item name="docx" xsi:type="number">1</item>

    – Magento_Bhurio
    Jun 24 at 11:03












  • This is adding doc and docx file but showing error. I am not able to figure out how to fix this.

    – Shiwani
    Jun 24 at 11:14















2














Please Look at here,



Please change this file




project/vendor/magento/module-cms/etc/di.xml




Add any extension you want to add <item name="docx" xsi:type="number">1</item>



<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="docx" 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 name="docx" 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="docx" xsi:type="number">1</item>
</item>







share|improve this answer

























  • This is not working.. already tried it

    – Shiwani
    Jun 24 at 11:00












  • Check my updated code.

    – Magento_Bhurio
    Jun 24 at 11:01











  • what you have updated in this code?

    – Shiwani
    Jun 24 at 11:03











  • In second add <item name="image_allowed" xsi:type="array"> add this line :- <item name="docx" xsi:type="number">1</item>

    – Magento_Bhurio
    Jun 24 at 11:03












  • This is adding doc and docx file but showing error. I am not able to figure out how to fix this.

    – Shiwani
    Jun 24 at 11:14













2












2








2







Please Look at here,



Please change this file




project/vendor/magento/module-cms/etc/di.xml




Add any extension you want to add <item name="docx" xsi:type="number">1</item>



<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="docx" 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 name="docx" 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="docx" xsi:type="number">1</item>
</item>







share|improve this answer















Please Look at here,



Please change this file




project/vendor/magento/module-cms/etc/di.xml




Add any extension you want to add <item name="docx" xsi:type="number">1</item>



<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="docx" 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 name="docx" 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="docx" xsi:type="number">1</item>
</item>








share|improve this answer














share|improve this answer



share|improve this answer








edited Jun 24 at 12:01

























answered Jun 24 at 10:57









Magento_BhurioMagento_Bhurio

7692 silver badges13 bronze badges




7692 silver badges13 bronze badges












  • This is not working.. already tried it

    – Shiwani
    Jun 24 at 11:00












  • Check my updated code.

    – Magento_Bhurio
    Jun 24 at 11:01











  • what you have updated in this code?

    – Shiwani
    Jun 24 at 11:03











  • In second add <item name="image_allowed" xsi:type="array"> add this line :- <item name="docx" xsi:type="number">1</item>

    – Magento_Bhurio
    Jun 24 at 11:03












  • This is adding doc and docx file but showing error. I am not able to figure out how to fix this.

    – Shiwani
    Jun 24 at 11:14

















  • This is not working.. already tried it

    – Shiwani
    Jun 24 at 11:00












  • Check my updated code.

    – Magento_Bhurio
    Jun 24 at 11:01











  • what you have updated in this code?

    – Shiwani
    Jun 24 at 11:03











  • In second add <item name="image_allowed" xsi:type="array"> add this line :- <item name="docx" xsi:type="number">1</item>

    – Magento_Bhurio
    Jun 24 at 11:03












  • This is adding doc and docx file but showing error. I am not able to figure out how to fix this.

    – Shiwani
    Jun 24 at 11:14
















This is not working.. already tried it

– Shiwani
Jun 24 at 11:00






This is not working.. already tried it

– Shiwani
Jun 24 at 11:00














Check my updated code.

– Magento_Bhurio
Jun 24 at 11:01





Check my updated code.

– Magento_Bhurio
Jun 24 at 11:01













what you have updated in this code?

– Shiwani
Jun 24 at 11:03





what you have updated in this code?

– Shiwani
Jun 24 at 11:03













In second add <item name="image_allowed" xsi:type="array"> add this line :- <item name="docx" xsi:type="number">1</item>

– Magento_Bhurio
Jun 24 at 11:03






In second add <item name="image_allowed" xsi:type="array"> add this line :- <item name="docx" xsi:type="number">1</item>

– Magento_Bhurio
Jun 24 at 11:03














This is adding doc and docx file but showing error. I am not able to figure out how to fix this.

– Shiwani
Jun 24 at 11:14





This is adding doc and docx file but showing error. I am not able to figure out how to fix this.

– Shiwani
Jun 24 at 11:14

















draft saved

draft discarded
















































Thanks for contributing an answer to Magento Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f279391%2fmagento-2-getting-error-unsupported-image-format-file-var-www-mysite-pub-med%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form