public function beforeSave(Event $event, Entity $entity)
    {
        $config = $this->_config;

        foreach ($config['fields'] as $field => $fieldOption) {
            $data = $entity->toArray();
            $virtualField = $field . $config['suffix'];

            if (!isset($data[$virtualField]) || !is_array($data[$virtualField])) {
                continue;
            }

            $file = $entity->get($virtualField);

            $error = $this->_triggerErrors($file);

            if ($error === false) {
                continue;
            } elseif (is_string($error)) {
                throw new \ErrorException($error);
            }

            if (!isset($fieldOption['path'])) {
                throw new \LogicException(__('The path for the {0} field is required.', $field));
            }

            if (isset($fieldOption['prefix']) && (is_bool($fieldOption['prefix']) || is_string($fieldOption['prefix']))) {
                $this->_prefix = $fieldOption['prefix'];
            }

            $extension = (new File($file['name'], false))->ext();
            $uploadPath = $this->_getUploadPath($entity, $fieldOption['path'], $extension);
            if (!$uploadPath) {
                throw new \ErrorException(__('Error to get the uploadPath.'));
            }

            $folder = new Folder($this->_config['root']);
            $folder->create($this->_config['root'] . dirname($uploadPath));

            if ($this->_moveFile($entity, $file['tmp_name'], $uploadPath, $field, $fieldOption)) {
                if (!$this->_prefix) {
                    $this->_prefix = '';
                }

                $entity->set($field, $this->_prefix . $uploadPath);
            }

            $entity->unsetProperty($virtualField);
        }
    }