case "preflight":
errorMessage = getPhrase(`wcf.upload.error.${validationError.code}`);
break;
+ case "validation":
+ errorMessage = getPhrase(`wcf.upload.validation.error.${validationError.code}`);
+ break;
default:
errorMessage = "Unrecognized error type: " + JSON.stringify(validationError);
case "preflight":
errorMessage = (0, Language_1.getPhrase)(`wcf.upload.error.${validationError.code}`);
break;
+ case "validation":
+ errorMessage = (0, Language_1.getPhrase)(`wcf.upload.validation.error.${validationError.code}`);
+ break;
default:
errorMessage = "Unrecognized error type: " + JSON.stringify(validationError);
break;
namespace wcf\system\endpoint\controller\core\files\upload;
use Laminas\Diactoros\Response\JsonResponse;
-use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
+use Psr\Http\Message\ServerRequestInterface;
use wcf\data\file\FileEditor;
use wcf\data\file\temporary\FileTemporary;
use wcf\data\file\temporary\FileTemporaryEditor;
unset($fileTemporary);
$processor = $file->getProcessor();
+
+ if ($processor !== null) {
+ try {
+ $processor->validateUpload($file);
+ } catch (UserInputException $exception) {
+ (new FileEditor($file))->delete();
+
+ throw new UserInputException('validation', $exception->getType());
+ }
+ }
+
$processor?->adopt($file, $context);
$generateThumbnails = false;
// There are no thumbnails in the default implementation.
}
+ #[\Override]
+ public function validateUpload(File $file): void
+ {
+ // There is no need to validate the uploaded file.
+ }
+
#[\Override]
public function countExistingFiles(array $context): ?int
{
use wcf\data\file\File;
use wcf\data\file\thumbnail\FileThumbnail;
+use wcf\system\exception\UserInputException;
/**
* File processors are responsible to validate and process any file uploads
*/
public function acceptUpload(string $filename, int $fileSize, array $context): FileProcessorPreflightResult;
+ /**
+ * Validates the uploaded file.
+ *
+ * @throws UserInputException if the file is invalid.
+ */
+ public function validateUpload(File $file): void;
+
/**
* Notifies the file processor that the upload of a file has been completed
* that belongs to this type.