Validation for file type not working in File Upload in Magento 2 Store ConfigurationCustom system configuration fieldsMagento direct sql query not working in my dynamic adminhtml module configProduct Custom Option “File Upload” not workingMagento model extension experiment, return: “class does not exist”Magento : Admin Form Input Type “file” Value not WorkingMagento 2 custom module configuration settings not display in adminGet upload_dir for custom system configuration file upload || getFieldConfig for custom system configurationMagento 2 Saving store configuration programatically in upgrade scriptmagento2 file upload Pdf not workingMagento 2 :upload file type restrict to pdf only

Are gliders susceptible to bird strikes?

Who voices the character "Finger" in The Fifth Element?

Was it really unprofessional of me to leave without asking for a raise first?

What exactly did Ant-Man see that made him say that their plan worked?

Losing queen and then winning the game

If two black hole event horizons overlap (touch) can they ever separate again?

Sacrifice blocking creature before damage is dealt no longer working (MtG Arena)?

What game is this character in the Pixels movie from?

Is it okay to fade a human face just to create some space to place important content over it?

Could human civilization live 150 years in a nuclear-powered aircraft carrier colony without resorting to mass killing/ cannibalism?

How receiver knows the exact frequency in the channel to "listen to"?

Closest Proximity of Oceans to Freshwater Springs

How did they film the Invisible Man being invisible, in 1933?

What do you call a notepad used to keep a record?

Is there reliable evidence that depleted uranium from the 1999 NATO bombing is causing cancer in Serbia?

Put my student loan in parents’ second mortgage - help?

Does a Hand Crossbow with the Repeating Shot Infusion still require a Free Hand to use?

Converting Geographic Coordinates into Lambert2008 coordinates

Can you actually break an FPGA by programming it wrong?

Company threatening to call my current job after I declined their offer

Reusable spacecraft: why still have fairings detach, instead of open/close?

13th chords on guitar

Why did NASA wet the road in front of the Space Shuttle crawler?

Comment traduire « That screams X »



Validation for file type not working in File Upload in Magento 2 Store Configuration


Custom system configuration fieldsMagento direct sql query not working in my dynamic adminhtml module configProduct Custom Option “File Upload” not workingMagento model extension experiment, return: “class does not exist”Magento : Admin Form Input Type “file” Value not WorkingMagento 2 custom module configuration settings not display in adminGet upload_dir for custom system configuration file upload || getFieldConfig for custom system configurationMagento 2 Saving store configuration programatically in upgrade scriptmagento2 file upload Pdf not workingMagento 2 :upload file type restrict to pdf only






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I am following below Article to upload file in store configuration:
https://www.mageplaza.com/devdocs/how-file-upload-sytem-configuration-magento-2.html



I have defined custom backend model as mentioned in this artice to validate my file type:



<?php

namespace VendorPackageModelConfigBackend;

class CustomFileType extends MagentoConfigModelConfigBackendFile

/**
* @return string[]
*/
public function getAllowedExtensions()
return ['csv'];


?>


and in system.xml, it's like this:



<field id="import" translate="label" type="MagentoConfigBlockSystemConfigFormFieldFile" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Import CSV</label>
<comment>Comment</comment>
<backend_model>VendorPackageModelConfigBackendCustomFileType</backend_model>
<upload_dir>upload</upload_dir>
</field>


but it's not working. I can upload image files too!!



What's wrong with this code?










share|improve this question






















  • Code looks fine. Did you run di:compile and flushed the cache as well?

    – Sukumar Gorai
    Jun 20 at 11:47












  • yes. I flushed the cache. do i need to run di:compile in developer mode too?

    – Khushbu
    Jun 20 at 11:50











  • Yes run once because if not compiled then might be an issue.

    – Sukumar Gorai
    Jun 20 at 11:56











  • Thank you @SukumarGorai. But i got the solution. See my answer.

    – Khushbu
    Jun 20 at 11:57












  • Yes I have checked. Happy coding!

    – Sukumar Gorai
    Jun 20 at 11:58

















0















I am following below Article to upload file in store configuration:
https://www.mageplaza.com/devdocs/how-file-upload-sytem-configuration-magento-2.html



I have defined custom backend model as mentioned in this artice to validate my file type:



<?php

namespace VendorPackageModelConfigBackend;

class CustomFileType extends MagentoConfigModelConfigBackendFile

/**
* @return string[]
*/
public function getAllowedExtensions()
return ['csv'];


?>


and in system.xml, it's like this:



<field id="import" translate="label" type="MagentoConfigBlockSystemConfigFormFieldFile" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Import CSV</label>
<comment>Comment</comment>
<backend_model>VendorPackageModelConfigBackendCustomFileType</backend_model>
<upload_dir>upload</upload_dir>
</field>


but it's not working. I can upload image files too!!



What's wrong with this code?










share|improve this question






















  • Code looks fine. Did you run di:compile and flushed the cache as well?

    – Sukumar Gorai
    Jun 20 at 11:47












  • yes. I flushed the cache. do i need to run di:compile in developer mode too?

    – Khushbu
    Jun 20 at 11:50











  • Yes run once because if not compiled then might be an issue.

    – Sukumar Gorai
    Jun 20 at 11:56











  • Thank you @SukumarGorai. But i got the solution. See my answer.

    – Khushbu
    Jun 20 at 11:57












  • Yes I have checked. Happy coding!

    – Sukumar Gorai
    Jun 20 at 11:58













0












0








0








I am following below Article to upload file in store configuration:
https://www.mageplaza.com/devdocs/how-file-upload-sytem-configuration-magento-2.html



I have defined custom backend model as mentioned in this artice to validate my file type:



<?php

namespace VendorPackageModelConfigBackend;

class CustomFileType extends MagentoConfigModelConfigBackendFile

/**
* @return string[]
*/
public function getAllowedExtensions()
return ['csv'];


?>


and in system.xml, it's like this:



<field id="import" translate="label" type="MagentoConfigBlockSystemConfigFormFieldFile" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Import CSV</label>
<comment>Comment</comment>
<backend_model>VendorPackageModelConfigBackendCustomFileType</backend_model>
<upload_dir>upload</upload_dir>
</field>


but it's not working. I can upload image files too!!



What's wrong with this code?










share|improve this question














I am following below Article to upload file in store configuration:
https://www.mageplaza.com/devdocs/how-file-upload-sytem-configuration-magento-2.html



I have defined custom backend model as mentioned in this artice to validate my file type:



<?php

namespace VendorPackageModelConfigBackend;

class CustomFileType extends MagentoConfigModelConfigBackendFile

/**
* @return string[]
*/
public function getAllowedExtensions()
return ['csv'];


?>


and in system.xml, it's like this:



<field id="import" translate="label" type="MagentoConfigBlockSystemConfigFormFieldFile" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Import CSV</label>
<comment>Comment</comment>
<backend_model>VendorPackageModelConfigBackendCustomFileType</backend_model>
<upload_dir>upload</upload_dir>
</field>


but it's not working. I can upload image files too!!



What's wrong with this code?







magento2 configuration file-upload custom-validation






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jun 20 at 11:29









KhushbuKhushbu

30713 bronze badges




30713 bronze badges












  • Code looks fine. Did you run di:compile and flushed the cache as well?

    – Sukumar Gorai
    Jun 20 at 11:47












  • yes. I flushed the cache. do i need to run di:compile in developer mode too?

    – Khushbu
    Jun 20 at 11:50











  • Yes run once because if not compiled then might be an issue.

    – Sukumar Gorai
    Jun 20 at 11:56











  • Thank you @SukumarGorai. But i got the solution. See my answer.

    – Khushbu
    Jun 20 at 11:57












  • Yes I have checked. Happy coding!

    – Sukumar Gorai
    Jun 20 at 11:58

















  • Code looks fine. Did you run di:compile and flushed the cache as well?

    – Sukumar Gorai
    Jun 20 at 11:47












  • yes. I flushed the cache. do i need to run di:compile in developer mode too?

    – Khushbu
    Jun 20 at 11:50











  • Yes run once because if not compiled then might be an issue.

    – Sukumar Gorai
    Jun 20 at 11:56











  • Thank you @SukumarGorai. But i got the solution. See my answer.

    – Khushbu
    Jun 20 at 11:57












  • Yes I have checked. Happy coding!

    – Sukumar Gorai
    Jun 20 at 11:58
















Code looks fine. Did you run di:compile and flushed the cache as well?

– Sukumar Gorai
Jun 20 at 11:47






Code looks fine. Did you run di:compile and flushed the cache as well?

– Sukumar Gorai
Jun 20 at 11:47














yes. I flushed the cache. do i need to run di:compile in developer mode too?

– Khushbu
Jun 20 at 11:50





yes. I flushed the cache. do i need to run di:compile in developer mode too?

– Khushbu
Jun 20 at 11:50













Yes run once because if not compiled then might be an issue.

– Sukumar Gorai
Jun 20 at 11:56





Yes run once because if not compiled then might be an issue.

– Sukumar Gorai
Jun 20 at 11:56













Thank you @SukumarGorai. But i got the solution. See my answer.

– Khushbu
Jun 20 at 11:57






Thank you @SukumarGorai. But i got the solution. See my answer.

– Khushbu
Jun 20 at 11:57














Yes I have checked. Happy coding!

– Sukumar Gorai
Jun 20 at 11:58





Yes I have checked. Happy coding!

– Sukumar Gorai
Jun 20 at 11:58










2 Answers
2






active

oldest

votes


















2














I found answer by referring




vendormagentomodule-configModelConfigBackendFile.php




Correct Function name is _getAllowedExtensions not getAllowedExtensions



So, correct method is:



public function _getAllowedExtensions() 
return ['csv'];






share|improve this answer























  • its not necessary

    – Rk Rathod
    Jun 20 at 12:17











  • You can try this code!

    – Khushbu
    Jun 20 at 12:25











  • i'm also try this

    – Rk Rathod
    Jun 20 at 12:27


















0














Replace backend_model with this :-



<backend_model>MagentoConfigModelConfigBackendFile</backend_model>





share|improve this answer























  • this is not working!

    – Khushbu
    Jun 20 at 11:49












  • i think your controller is not called

    – Rk Rathod
    Jun 20 at 11:51













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%2f279022%2fvalidation-for-file-type-not-working-in-file-upload-in-magento-2-store-configura%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









2














I found answer by referring




vendormagentomodule-configModelConfigBackendFile.php




Correct Function name is _getAllowedExtensions not getAllowedExtensions



So, correct method is:



public function _getAllowedExtensions() 
return ['csv'];






share|improve this answer























  • its not necessary

    – Rk Rathod
    Jun 20 at 12:17











  • You can try this code!

    – Khushbu
    Jun 20 at 12:25











  • i'm also try this

    – Rk Rathod
    Jun 20 at 12:27















2














I found answer by referring




vendormagentomodule-configModelConfigBackendFile.php




Correct Function name is _getAllowedExtensions not getAllowedExtensions



So, correct method is:



public function _getAllowedExtensions() 
return ['csv'];






share|improve this answer























  • its not necessary

    – Rk Rathod
    Jun 20 at 12:17











  • You can try this code!

    – Khushbu
    Jun 20 at 12:25











  • i'm also try this

    – Rk Rathod
    Jun 20 at 12:27













2












2








2







I found answer by referring




vendormagentomodule-configModelConfigBackendFile.php




Correct Function name is _getAllowedExtensions not getAllowedExtensions



So, correct method is:



public function _getAllowedExtensions() 
return ['csv'];






share|improve this answer













I found answer by referring




vendormagentomodule-configModelConfigBackendFile.php




Correct Function name is _getAllowedExtensions not getAllowedExtensions



So, correct method is:



public function _getAllowedExtensions() 
return ['csv'];







share|improve this answer












share|improve this answer



share|improve this answer










answered Jun 20 at 11:55









KhushbuKhushbu

30713 bronze badges




30713 bronze badges












  • its not necessary

    – Rk Rathod
    Jun 20 at 12:17











  • You can try this code!

    – Khushbu
    Jun 20 at 12:25











  • i'm also try this

    – Rk Rathod
    Jun 20 at 12:27

















  • its not necessary

    – Rk Rathod
    Jun 20 at 12:17











  • You can try this code!

    – Khushbu
    Jun 20 at 12:25











  • i'm also try this

    – Rk Rathod
    Jun 20 at 12:27
















its not necessary

– Rk Rathod
Jun 20 at 12:17





its not necessary

– Rk Rathod
Jun 20 at 12:17













You can try this code!

– Khushbu
Jun 20 at 12:25





You can try this code!

– Khushbu
Jun 20 at 12:25













i'm also try this

– Rk Rathod
Jun 20 at 12:27





i'm also try this

– Rk Rathod
Jun 20 at 12:27













0














Replace backend_model with this :-



<backend_model>MagentoConfigModelConfigBackendFile</backend_model>





share|improve this answer























  • this is not working!

    – Khushbu
    Jun 20 at 11:49












  • i think your controller is not called

    – Rk Rathod
    Jun 20 at 11:51















0














Replace backend_model with this :-



<backend_model>MagentoConfigModelConfigBackendFile</backend_model>





share|improve this answer























  • this is not working!

    – Khushbu
    Jun 20 at 11:49












  • i think your controller is not called

    – Rk Rathod
    Jun 20 at 11:51













0












0








0







Replace backend_model with this :-



<backend_model>MagentoConfigModelConfigBackendFile</backend_model>





share|improve this answer













Replace backend_model with this :-



<backend_model>MagentoConfigModelConfigBackendFile</backend_model>






share|improve this answer












share|improve this answer



share|improve this answer










answered Jun 20 at 11:39









Rk RathodRk Rathod

2,4233 silver badges18 bronze badges




2,4233 silver badges18 bronze badges












  • this is not working!

    – Khushbu
    Jun 20 at 11:49












  • i think your controller is not called

    – Rk Rathod
    Jun 20 at 11:51

















  • this is not working!

    – Khushbu
    Jun 20 at 11:49












  • i think your controller is not called

    – Rk Rathod
    Jun 20 at 11:51
















this is not working!

– Khushbu
Jun 20 at 11:49






this is not working!

– Khushbu
Jun 20 at 11:49














i think your controller is not called

– Rk Rathod
Jun 20 at 11:51





i think your controller is not called

– Rk Rathod
Jun 20 at 11:51

















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%2f279022%2fvalidation-for-file-type-not-working-in-file-upload-in-magento-2-store-configura%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

Get RecordId in LWC From Community PageLWC Community recordId undefinedhow to get Personal Access Token from my integrated application LWC. I am using js onlylwc quick action from Opportunity page(aura:component) and not getting @api recordIdLWC Community recordId undefinedLWC - How to get label name of buttonsLWC: Add a region in custom community themeVisual force page redirection from lightning communityLWC NavigationMixin does not work in CommunityInvoking LWC component from a plain URL - Read URL Parameter inside LWCLWC download PDF fileLWC Get Pick-list Field Values