Can't upload files with CKEditor5 file upload

Created on 20 December 2022, almost 3 years ago
Updated 30 August 2024, about 1 year ago

Problem/Motivation

The current implementation of the File Uplload Secure Validator gives a conflict with the default File upload option in CKEditor5.

Steps to reproduce

  1. setup a clean Drupal 9.5.x or Drupal 10.0.x installation.
  2. Configure a text format that uses the CKEditor5 and enable image uploads for the default image button
  3. Go to a content page with the CKEditor and try to upload a file with the image button

The above steps wil result in error stating the file couldn't be uploaded. And the following message in the watchdog log:
Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException: Object(Drupal\Core\Entity\Plugin\DataType\EntityAdapter): Caught an InvalidArgumentException; cannot validate missing file requested as public://inline-images/test.jpg in Drupal\ckeditor5\Controller\CKEditor5ImageController->upload() (line 181 of /var/lib/tugboat/stm/web/core/modules/ckeditor5/src/Controller/CKEditor5ImageController.php).

Proposed resolution

Looking at CKEditor5ImageController.php, it seems the issue comes from the fact that the file object is being validated before its actually moved to the correct location. So the file is still located in the tmp folder, while the uri on the file object is already pointing to the pbulic folder.

And on line 70 of the FileUploadSecureValidator service the file uri is being used to try and determine the files mimetype. Which of course results in the FileNotFoundException being thrown, resulting in the above watchdog error.

Not sure if the issue can be resolved in this module, or if it requires changes in the Drupal Core itself.

🐛 Bug report
Status

Closed: outdated

Version

2.0

Component

Code

Created by

🇳🇱Netherlands Da_Cloud

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024