Problem/Motivation

In `\Drupal\plupload\Element\PlUploadFile::validatePlUploadFile` a file entity is created and passed through to `file_validate` without the filesize populated. This can cause issue for anything that is calling getSize inside hook_file_validate.

Steps to reproduce

This code can be used to validate the filesize is missing.

function example_file_validate(Drupal\file\FileInterface $file) {
  if (!$file->getSize()) {
      $errors[] = t('The file is empty (%filesize).', ['%filesize' => format_size($file->getSize())]);
  }
}

Proposed resolution

Add filesize when creating the file entity.

CommentFileSizeAuthor
#2 3284986-missing-filesize-2.patch609 bytesericgsmith

Comments

ericgsmith created an issue. See original summary.

ericgsmith’s picture

Status: Active » Needs review
StatusFileSize
new609 bytes

Patch attached

  • budalokko committed 3a0ad557 on 2.0.x authored by ericgsmith
    Issue #3284986 by ericgsmith: Filesize not provided in PlUploadFile::...
budalokko’s picture

Status: Needs review » Fixed

Files created by core "managed_file" FAPI element do have it, so yes, files created by our module should have it too.

Committed, thanks !!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.