FriendsOfCake / cakephp-upload

CakePHP: Handle file uploading sans ridiculous automagic
https://cakephp-upload.readthedocs.io/
MIT License
551 stars 255 forks source link

Unknown type "upload.file" #543

Closed enviniom closed 4 years ago

enviniom commented 4 years ago

Hi. I am using CakePHP 4 and this plugin to upload files. I configured the plugin (V 5.0.0 RC) with the advanced configuration adding a behavior in the table as shown in the docs, as follows

    $this->addBehavior('Josegonzalez/Upload.Upload', [
        'pdf' => [
            'fields' => [
                'dir' => 'pdf_dir',
            ],
            'nameCallback' => function ($table, $entity, $data, $field, $settings) {
                $extension = pathinfo($data['name'], PATHINFO_EXTENSION);
                return strtolower("ot" . "-" . Time::now()->i18nFormat('yyyy-MM-dd.HH:mm:ss') . '.' . $extension);
            },
            'deleteCallback' => function ($path, $entity, $field, $settings) {
                // When deleting the entity, both the original and the thumbnail will be removed
                // when keepFilesOnDelete is set to false
                return [
                    $path . $entity->{$field},
                ];
            },
            'keepFilesOnDelete' => false
        ],
    ]);

Saving a new record without a file works fine, but when uploading a file I get the error: Unknown type "upload.file" InvalidArgumentException

ADmad commented 4 years ago

You need to load the plugin using $this->addPlugin() in your Application::bootstrap().

angelxmoreno commented 6 days ago

I was encountering this issue but only during tests. After some digging I was able to resolve it thanks to #574

https://github.com/FriendsOfCake/cakephp-upload/issues/574#issuecomment-2356797985