Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

UploadField validation and allowed extensions


Go to End


2 Posts   1727 Views

Avatar
martbarr

Community Member, 59 Posts

2 October 2014 at 10:01pm

Edited: 02/10/2014 10:04pm

Hi I have a regular uploadField where I use:-

   function getCMSFields()
    {
        $fields = parent::getCMSFields();
		$uploadField = new UploadField( $name = 'RotaFile', $title = 'Upload rota excel file' );   
        	$uploadField->setFolderName('/adminfiles/rota_uploads');
   	        $uploadField->setAllowedExtensions(array('xlsm','xlsx'));
		$sizeBytes = 3 * 1024 * 1024 ; // 3 MB in bytes
		$uploadField->getValidator()->setAllowedMaxFileSize($sizeBytes);
		$uploadField->setCanPreviewFolder(true);
          	$fields->addFieldToTab( 'Root.ExcelUpload', $uploadField);
		return $fields;
    } 

uploadField validation passes and returns valid - but it then goes into dataobject::write(...) to do a second validation check which fails with "Forbidden" because xlsm is not in the "global" allowed list.

I see in databobject::write(...)

if(Config::inst()->get('DataObject', 'validation_enabled')) {
			$valid = $this->validate();

So it's doing a second check (that I don't really want) on the allowed extensions which fails as it just uses the global list which has no xlsm in it..

Can I switch `validation_enabled` off just for this one uploadFile object?
- or do I need to add xlsm file type to my global list of allowed extensions (using File and allowed extensions in _config.yml)?

thanks as ever!
Martin

Avatar
UncleCheese

Forum Moderator, 4102 Posts

3 October 2014 at 2:48pm

Best thing to do is append the list of allowed_extensions in your config.

File:
allowed_extensions:
- xlsx