This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

Demetrius
Demetrius

When I try to upload a PDF file, I get an error saying the filetype is not a valid one. Zip files upload without a problem. Is there any way I can set which filetypes to accept?

andrew
andrew

That's set on line 56 in modules/cms/widgets/AssetList.php It can be overridden.

* @var array A list of default allowed file types.
* This parameter can be overridden with the cms.allowedAssetTypes configuration option.
*/
Demetrius
Demetrius

Nevermind. It does upload some pdf files, however for other's it says the file is not valid. Might be something related to the file's header.

Last updated

andrew
andrew

Add to the bottom of app/config/cms.php

     /*
    |--------------------------------------------------------------------------
    | Specifies the allowed file types.
    |--------------------------------------------------------------------------
    |
    |
    */
   'allowedAssetTypes' => ['jpg','jpeg','bmp','png','gif','css','js','woff','svg','ttf','eot','json','md','less','sass','scss','pdf'],

Last updated

Demetrius
Demetrius

I tried several things, but the problem is still not solved.

I added said configuration options and it allows me to upload PDF files, however, certain files it accepts while it doesn't accept others. Seems like something is going wrong with the isValid() function (Symfony) for asset uploads. As far as I know October only checks the file extension for validity, but not the mime/file-header types.

andrew
andrew

It does only check the extension.

Is the error not allow or not a valid file?

            if (!in_array($ext, $allowedAssetTypes))
                throw new ApplicationException(Lang::get('cms::lang.asset.type_not_allowed', ['allowed_types'=>implode(', ', $allowedAssetTypes)]));

            if (!$uploadedFile->isValid())
                throw new ApplicationException(Lang::get('cms::lang.asset.file_not_valid'));
Demetrius
Demetrius

It doesn't just check the extension, apparently it directs the file to a Symfony function and check for the mimetype/headers as well. It keeps returning a "not a valid file" error. I can upload some PDFs, while others generate an error.

planetadeleste
planetadeleste

@Demetrius I think the problem is on the saved version of your PDF. If your are saved from Illustrator, try to use some old version and uncheck the option "editable by Illustrator" (or something like that).

Demetrius
Demetrius

I don't think it is, really. Since last time I have also had problems uploading several jpeg and zip files, which are marked as invalid files. I tried several ways of archiving and saving, but nothing seems to work for it.

planetadeleste
planetadeleste

Can you try on other server? or maybe using Vagrant to install a virtual server.

Enecs
Enecs

hi,

I know this thread is a year old but I have a problem with setting allowedAssetTypes. i've copied the allowed types but still if i try to upload something i have to set file types to everything and then i get a red box with following error: You can't upload files of this type.

is this changed in the latest version?

update: found it myself i had to add fileTypes in the fields.yaml

Last updated

Keios
Keios

If someone finds this topic wondering about file types for MediaManager, it's kind of hidden in the docs, but to allow more filetypes you have to overwrite default settings (defined in October\Rain\Filesystem\Definitions) in cms.php config. Paste and customize array like this at the bottom of the config:

 'fileDefinitions' => [
        'defaultExtensions' => [
            'jpg',
            'jpeg',
            'bmp',
            'png',
            'gif',
            'svg',
            'js',
            'map',
            'ico',
            'css',
            'less',
            'scss',
            'pdf',
            'swf',
            'txt',
            'xml',
            'xls',
            'eot',
            'woff',
            'woff2',
            'ttf',
            'flv',
            'wmv',
            'mp3',
            'ogg',
            'wav',
            'avi',
            'mov',
            'mp4',
            'mpeg',
            'webm',
            'mkv',
            'rar',
            'zip'
        ]
    ]

Last updated

urgotto22588
urgotto22588

specify array of extensions in config/cms.php -> fileDefinitions[assetExtensions['ext1','ext2'...]]

diezit.
diezit.

If you found this topic in Google (i did), note the config settings have changed and it now expects its values in snake_case instead of CamelCase.

Putting the following in config/cms.php should do the job (add the extensions you want, obviously);

    'file_definitions' => [
        'default_extensions' => [
            'jpg',
            'jpeg',
            'bmp',
            'png',
            'gif',
            'svg',
            'js',
            'map',
            'ico',
            'css',
            'less',
            'json',
            'scss',
            'pdf',
            'swf',
            'txt',
            'xml',
            'xls',
            'eot',
            'woff',
            'woff2',
            'ttf',
            'flv',
            'wmv',
            'mp3',
            'ogg',
            'wav',
            'avi',
            'mov',
            'mp4',
            'mpeg',
            'webm',
            'mkv',
            'rar',
            'zip'
        ]
    ]

1-14 of 14

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.