Create an UploadedFile validator and deprecate error checking methods on UploadedFileInterface

Created on 19 July 2023, 11 months ago
Updated 23 October 2023, 8 months ago

Problem/Motivation

In πŸ“Œ [PP-4] Unify file upload logic of REST and JSON:API Postponed we are wanting to upload files directly via octet-stream and Content-Disposition header, and because it doesn't use $_POST variables we can't use Symfony UploadedFile object. However, in \Drupal\file\Upload\FileUploadHandler::handleFileUpload() we call isValid() and assume we have an instance of UploadedFile.

This is most likely due to copying existing code.

Steps to reproduce

Proposed resolution

  • Deprecate \Drupal\file\Upload\UploadedFileInterface::isValid() ::getError() and ::getErrorMessage()
  • Add an \Drupal\file\Validation\UploadedFileValidator that validates uploaded files using \Drupal\file\Validation\Constraint\UploadedFileConstraint and \Drupal\file\Validation\Constraint\UploadedFileConstraintValidator
  • Remove the checks for isValid() and throwing exceptions in FileUploadHandler::handleFileUpload()
  • Call UploadedFileValidator::validate() and check for constraint violations instead

Remaining tasks

Do it.

User interface changes

API changes

\Drupal\file\Upload\UploadedFileInterface::isValid() ::getError() and ::getErrorMessage() are deprecated
A new UploadedFileInterface::validate() method is added, that throws \Symfony\Component\HttpFoundation\File\Exception\FileException and sub-classes.

Data model changes

Release notes snippet

πŸ“Œ Task
Status

Fixed

Version

11.0 πŸ”₯

Component
File moduleΒ  β†’

Last updated 3 days ago

Created by

πŸ‡¦πŸ‡ΊAustralia kim.pepper πŸ„β€β™‚οΈπŸ‡¦πŸ‡ΊSydney, Australia

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024