Can't upload files with CKEditor5 file upload

Created on 20 December 2022, almost 2 years ago
Updated 30 August 2024, 3 months 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.

  • 🇫🇷France hassebasse

    I'm on D10.1

    I had the same problem, and I figured out it was connected to activating the Blazy filter in the text editor settings. So upload impossible with the Blazy filter activated in the text editor settings, while upload possible if desactivating the Blazy filter in the text editor settings.

    Maybe it is rather a Blazy issue?

    Symfony\Component\HttpKernel\Exception\HttpException: Temporary file could not be moved to file location in Drupal\ckeditor5\Controller\CKEditor5ImageController->upload() (line 188 of /home/my-domain/public_html/drupal/web/core/modules/ckeditor5/src/Controller/CKEditor5ImageController.php).

  • 🇮🇳India ramprassad

    I'm also facing this issue in drupal 10.1.3 with ckeditor 5. This patch works fine, so created a patch so it can be applied.

  • 🇵🇱Poland azovsky

    Thanks @ramprassad! The #5 patch is working for me!

  • 🇲🇽Mexico edgar.aguilar Tabasco

    @ramprassad! The #5 patch is working for me! thanks!!

  • 🇧🇷Brazil larruda

    Had to port the patch to work with 10.2.0.
    Haven't fully tested yet, but apparently fixes the problem.

    I believe a new issue must be raised in core, otherwise this patch will not be committed.

  • Status changed to Needs review 11 months ago
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update 11 months ago
    Patch Failed to Apply
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update 11 months ago
    Patch Failed to Apply
  • 🇧🇷Brazil larruda

    Just raised an issue in core referencing this one
    https://www.drupal.org/project/drupal/issues/3410827 🐛 Can't upload files Active

  • 🇩🇪Germany Franz-m

    In my case - D10.2.2 - I did not succeed. Hopefully this log can help ...

    Gathering patches for dependencies. This might take a minute.
       - Installing drupal/core-recommended (10.2.2)
       - Applying patches for drupal/core-recommended
         3328277-ckeditor5-upload-image-2.patch (Cke5-Image-Upload)
     
     In RemoteFilesystem.php line 108:
                                                                                    
       [TypeError]                                                                  
       Composer\Util\RemoteFilesystem::copy(): Argument #1 ($originUrl) must be of  
        type string, null given,
  • 🇮🇳India Sandeep_k New Delhi

    @larruda, I've tested this patch- 3328277-ckeditor5-upload-image-2.patch on Drupal version- 9.5, I was able to reproduce this issue but while applying the patch I was getting an error & The patch didn't get applied successfully for me. (Error attached)

  • 🇫🇷France frondeau Nantes, FRANCE

    Hello,
    On Drupal 9.5.11,
    I was looking for a patch to solve the CKEDITOR5 image upload.
    I've applied the first patch, https://www.drupal.org/files/issues/2023-09-20/3328277-ckeditor5-upload-image.patch ,

    • with my user profile, administration language, on a choosen language FRENCH: the patch won't work.
    • with my user profile, administration language, on a choosen language NO PREFERENCE: it is working, as it is without this patch.

    So this patch may fix a bug but not the concerned one (CKEDITOR5 Images upload).
    Sorry to fix this conversation but I think it is important to add this detail.

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.4 + Environment: PHP 8.2 & MySQL 8
    last update 10 months ago
    Patch Failed to Apply
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.4 + Environment: PHP 8.2 & MySQL 8
    last update 10 months ago
    Patch Failed to Apply
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.4 + Environment: PHP 8.2 & MySQL 8
    last update 10 months ago
    Patch Failed to Apply
  • 🇳🇱Netherlands Ronald van Belzen

    I wonder whether this issue will also solve the scenario when copy-and-pasting multiple images into the editor. This results in only 1 image being saved, while the other images encounter the error:

    Symfony\Component\HttpKernel\Exception\HttpException: File "public://inline-images/image.png" is already locked for writing. in Drupal\ckeditor5\Controller\CKEditor5ImageController->upload() (line 167 of /var/www/html/web/core/modules/ckeditor5/src/Controller/CKEditor5ImageController.php).

    Not been able to check the patch, but maybe this is of interest.

  • 🇨🇭Switzerland stefanos.petrakis@gmail.com Biel, Switzerland

    Currently from D 10.3 on (and D 11) this should be fixed according to 🐛 [PP-1] CKEditor file upload sets file URI prior to validation, causing validators to be unable to find the file. Postponed

    Note: According to this comment 🐛 [PP-1] CKEditor file upload sets file URI prior to validation, causing validators to be unable to find the file. Postponed :

    Patches for 10.1 and 10.2 are available are issue forks within the main issue.

    Although the 11.x commit applies cleanly against 10.2, it's not compatible with the API changes introduced in #3375447: Create an UploadedFile validator and deprecate error checking methods on UploadedFileInterface as stated in #49, and the 10.2 patch (if applied) should be subsequently removed upon updating to 10.3.

    Going to move this to "Outdated" since the reported problem seems to be fixed in core.

  • Status changed to Closed: outdated 3 months ago
  • 🇨🇭Switzerland stefanos.petrakis@gmail.com Biel, Switzerland
Production build 0.71.5 2024