Managed-file uploads do not support multiple actions per submit, and can't be replaced without multiple submits.

Created on 17 December 2020, over 4 years ago
Updated 1 April 2025, about 1 month ago

Problem/Motivation

I'm using the upload feature in an edit form.
I can successfully upload or delete an image file, but a replacement,
removing an existing file followed by an Upload with the same submit
results in the persistence of the "removed" file plus the new file
with a status code of zero (0).
Displaying the replaced file after a short time causes a wsod,
since CRON removes temporary files.

Steps to reproduce

This can be reproduced by downloading the hello and common
modules here.
Applicable code is also posted in the files section.
Screen shotsin the files illustrate the issue. They are prefixed with the same step Ids (1a - 5a)
as their explanations below:

1a. Controller image with original file (Louvre 124).
1b. Original file_managed view.
2a Edit image before Removal.
2b. file_managed view before removal (same as 1b).
3a. Edit image after Removal but before Addition.
3b. file_managed view after removal but before addition (same as 1b).
3c. File directory view before submit. Only the original file (Louvre 124) is shown.
4a. Edit image after addition of new file (Louvre 132) but before the Submit action.
4b. File directory view after submit. Both files are stored.
4c. file_managed view after submit. showing new file with status=0 and the original file (louvre124).
5a. Controller image after the Submit of the Edit image showing only the new file (Louvre132).

Proposed resolution

I'm not familiar with the Drupal image system and can't be sure of the cause or offer a resolution.
Therefore I'm initially submitting it as a support request. If anyone finds a correction or a workaround, I'll use that. If the managed file works as designed, I'll change the status to a new feature request. If it's an error, I'll change the status to a bug report. Any comments are appreciated.

Remaining tasks

I'm not familiar with the Drupal image system

User interface changes

I added a workaround to change the status to permanent in the Controller module
of another module (asset), but the old, replaced file remains.
I also added a warning message.

API changes

Not applicable.

Data model changes

Not applicable.

Release notes snippet

None.

πŸ› Bug report
Status

Postponed: needs info

Version

11.0 πŸ”₯

Component

file system

Created by

πŸ‡ΊπŸ‡ΈUnited States othdvlpr

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.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Hello this came up as a daily BSI target, since it's been a few years wonder if still experiencing this in D11?

  • πŸ‡ΊπŸ‡ΈUnited States othdvlpr

    Yes. I'm running drupal core 11.1.6 on WSL and 11.1.5 on Ubuntu Server. All add/update attempts fail on Ubuntu Server since I updated the latest file upload_validators to comply with version 11 requirements; and I receive an Nginx warning since I'm running Nginx 1.24.0 on Ubuntu Server. I've attached some screenshots from both WSL and UbuntuServer and a managed_file snippet. Please let me know if you need further info.
    thanks for getting back to me.

  • πŸ‡¦πŸ‡ΊAustralia kim.pepper πŸ„β€β™‚οΈπŸ‡¦πŸ‡ΊSydney, Australia
            'FileImageDimensions' => ['maxDimensions' => 50 * 50],
    

    Do you mean ['maxDimensions' => '50x50'] here?

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

    I tried using your '50x50' suggestion on both the Ubuntu Server add and update with the same result, no image change or update. I also tried commenting out the 'FileImageDimensions' => ['maxDimensions' => '50x50' ] entry entirely with the same failure.
    Originally, I was using
    https://www.drupal.org/node/3363700 β†’
    as a guide. It didn't specify the format of
    $max_filesize, so I just used the m * n format,depicted the below article, for the old file_validate_size format.
    https://drupal.stackexchange.com/questions/65348/how-to-validate-file-si....
    Document clarification on $max_filesize would be useful.

Production build 0.71.5 2024