public function uploadAction()
    {
        if ($this->request->hasFiles() == true) {
            $this->initializeScaffolding();
            $form = $this->scaffolding->getForm();
            $name = key($_FILES);
            /** @var \Vegas\Forms\Element\Upload $uploadElement */
            $uploadElement = $form->get($name);
            $model = $uploadElement->getModel();

            $path = $uploadElement->getPath();
            $maxFileSize = $uploadElement->getMaxFileSize();
            $minFileSize = $uploadElement->getMinFileSize();

            foreach ($this->request->getUploadedFiles() as $file) {
                $fileName = $file->getName();
                $fileSize = $file->getSize();
                $fileType = $file->getRealType();
                $fileExtensions = pathinfo($fileName, PATHINFO_EXTENSION);

                $allowed = $uploadElement->getAllowedExtensions();
                if (!empty($allowed)) {
                    if (!in_array($fileExtensions, $allowed)) {
                        throw new ForbiddenFileExtensionException();
                    }
                }

                $forbidden = $uploadElement->getForbiddenExtensions();
                if (!empty($forbidden)) {
                    if (in_array($fileExtensions, $forbidden)) {
                        throw new ForbiddenFileExtensionException();
                    }
                }

                $allowedMime = $uploadElement->getAllowedMimeTypes();
                if (!empty($allowedMime)) {
                    if (!in_array($fileType, $allowedMime)) {
                        throw new ForbiddenFileMimeTypeException();
                    }
                }

                $forbiddenMime = $uploadElement->getForbiddenMimeTypes();
                if (!empty($forbiddenMime)) {
                    if (in_array($fileType, $forbiddenMime)) {
                        throw new ForbiddenFileMimeTypeException();
                    }
                }

                if (!empty($maxFileSize)) {
                    if ($fileSize > $this->convertFileSizeToBytes($maxFileSize)) {
                        throw new \Exception('s');
                    }
                }

                if (!empty($minFileSize)) {
                    if ($fileSize < $this->convertFileSizeToBytes($minFileSize)) {
                        throw new \Exception('s');
                    }
                }

                if (empty($path)) {
                    $path = 'files/';
                }

                $model->name = $fileName;
                $model->mime_type = $fileType;
                $model->path = $path;
                $model->save();

                $file->moveTo($path . $model->_id);
                return $this->response->setJsonContent((string) $model->_id);
            }
        }
        $this->view->setRenderLevel(View::LEVEL_NO_RENDER);
    }