private function handleUploadFiles(Request $request, $namespace, $files = null)
    {
        $filesToProcess = $this->getFilesToProcess($request, $namespace, $files);

        /** @var \Sirius\Upload\Result\Collection $result */
        $result = $this->app['upload']->process($filesToProcess);

        if ($result->isValid()) {
            if (!$this->app['config']->get('general/upload/autoconfirm')) {
                // Remove the .lock file attached to the file
                $result->confirm();
            }

            $successfulFiles = [];
            foreach ($result as $resultFile) {
                $successfulFiles[] = $this->filesystem()->toJs($namespace . '://' . $resultFile->name);
            }

            return $successfulFiles;
        }

        // The file that was saved during process() has a .lock file attached
        // and can now be cleared, in the case where form processing fails
        try {
            $result->clear();
        } catch (\Exception $e) {
            // It's an error state anyway
        }

        $errorFiles = [];
        foreach ($result as $resultFile) {
            $errors = $resultFile->getMessages();
            $errorFiles[] = [
                    'name'  => $resultFile->original_name,
                    'error' => (string) $errors[0],
                ];
        }

        return $errorFiles;
    }