Image uploads fail

Created on 25 January 2024, 11 months ago

Hi,

with Plupload (7.x-2.x-dev) and FileField Sources Plupload (7.x-1.1), image uploads fail. This affects as well the last recommended release plupload- 7.x-1.7 from 2014-Nov-07.

Error message: "The specified file ….jpg could not be uploaded. The image file is invalid or the image type is not allowed. Allowed types: Only JPEG, PNG and GIF images are allowed."

File type and file size is within the defined parameters, meaning: uploading file type JPEG should be allowed, file size is limited to 50 MB, actual file size is 72 kB.

The behaviour of the Plupload widget is like so:

  • Dragging a number of image files, e.g. 10 files, into the upload widget (labeled with "Drag files here");
  • Click "Start upload" button;
  • Error message as stated above appears;
  • Upload widget appears a 2nd time;
  • Repeat procedure;
  • Upload starts, now files are processed;
  • One file is discarded, e.g. from 10 files in the upload widget, only 9 are uploaded. It is impossible to upload the missing file.

This is nicely reproducable. If I upload 3 images, only 2 files are uploaded.

I believe the bug is a regression introduced with Drupal core 7.99 as image uploads worked perfectly fine before (for years).

Any ideas what could have caused this?

🐛 Bug report
Status

Active

Version

2.1

Component

Code

Created by

🇩🇪Germany asb

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

Comments & Activities

  • Issue created by @asb
  • 🇩🇪Germany asb

    Correction:

    Actually, Plupload 7.x-2.x-dev and 7.x-1.7 behave differently.

    • The procedure described above (upload files a 2nd time, plupload discards one file of the batch) applies only to 7.x-1.7.
    • Plupload 7.x-2.x-dev makes it completely impossible to upload image files. Though, still the same error message

    I reverted back to Plupload 7.x-1.7 and the dated library in version 1.5.8 which gives me the described behaviour: first upload attempt - error message - second upload attempt - files are uploaded, but one from the batch is discarded.

  • 🇪🇸Spain budalokko Girona

    Most probably It won't make It work, but wanted to clarify that 7.x-2.x-dev expects a diferent version of plupload library, probably something around 2.1 or 2.3.

  • 🇩🇪Germany asb

    In combination with plupload-7.x-2.x-dev, I used 'Plupload 2.3.9 AGPLv3' (from https://github.com/moxiecode/plupload/archive/v2.3.9.zip). According to ./admin/reports/status, the plupload module seems to have been happy with it (Status Report complained in combo with 1.5.8).

    However, I noticed that ./admin/reports/libraries lists the libraries (both versions) as "Unregistered" (= "These libraries were found in the filesystem but there is no metadata about them", opposed to "Installed" = "These libraries are registered and installed correctly". I have no idea if that "Installed" vs. "Unregistered" status is merely cosmetic or has any functional impact, but I doubt that it is relevant to the file upload issue I am encountering (unless that is handled more strict since Drupal core 7.99).

  • 🇪🇸Spain budalokko Girona

    This is the change in core that makes plupload fail since 7.99 -> https://www.drupal.org/node/2345695

    The removal of this line in modules/image/image.field.inc works around the issue:

    $elements[$delta]['#upload_validators']['file_validate_is_image'] = array();
    

    The commit -> https://git.drupalcode.org/project/drupal/-/commit/fd71fedd655b76e3652fc...

    Now we just need a proper fix :)

  • 🇩🇪Germany asb

    @budalokko: Thank you!

    I removed this line of code in ./modules/image/image.field.inc, and the error is fully gone. No more bogus error messages, no more silently discarded image files. Excellent!

    This applies to Plupload module 7.x-1.7 and the library in version 1.5.8.

    Regarding that Drupal core issue #2345695 with status "Closed (fixed)", it simply introduced a regression affecting real data by attempting to fix a nothingburger about a fringe case. Since the broken validation routine is in Drupal core, Plupload module can not fix it or work around it, right?

  • 🇭🇺Hungary fox mulder

    a possible workaround without patching core:

    function my_custom_module__field_widget_form_alter(&$element, &$form_state, $context) {
      if ($context['field']['type'] == 'image') {
        foreach ($element as $delta => $child) {
          if (isset($child['#upload_validators']['file_validate_is_image']) && is_array($child['#upload_validators']['file_validate_is_image']) && empty($child['#upload_validators']['file_validate_is_image'])) {
            unset($element[$delta]['#upload_validators']['file_validate_is_image']);
          } 
        }
      }
    }
  • 🇬🇧United Kingdom Ollie222

    I've just come across this issue and the fix in #8 has sorted my problem.

    I've not checked to see if there are any security issues with removing that line however the system I needed it for is internal anyway and only used by a couple of known users so it's not a problem in my case.

Production build 0.71.5 2024