"No media files have been provided"

Created on 4 December 2023, about 1 year ago
Updated 19 December 2023, about 1 year ago

Problem/Motivation
When uploading a file, I'm hit with `No media files have been provided`

All code mentioned is from /media_bulk_upload/src/Form/MediaBulkUploadForm.php
I checked `validateForm` method and saw the following:

<?php
    $uploaded_files = $form_state->getValue(['file_upload', 'uploaded_files']);
    if (empty($uploaded_files)) {
      $form_state->setErrorByName('file_upload', $this->t('No media files have been provided.'));
    }
    else {
      foreach ($uploaded_files as $uploaded_file) {
       $file = $this->fileStorage->create([
          'uri' => $uploaded_file['path']
        ]);

}
?>

I could be reading this wrong, but `$uploaded_files = $form_state->getValue(['file_upload', 'uploaded_files']);` doesn't work.

If I change it to `$uploaded_files = $form_state->getValue('file_upload');` then I can now by pass the validation, but now when you go further down the code its expecting an array of files with keys such as `path` but `$uploaded_files` would only return a string (file id number at this point).

Also the following code is trying to create a file, but at this point the file has been created just that the status has been set to 0.

<?php
        $file = $this->fileStorage->create([
          'uri' => $uploaded_file['path']
        ]);
?>

Because module was updated in April and I haven't seen an issue about this, I suspect i'm doing something wrong or have clearly missed something.

I am currently on Drupal 10.1.6.
Just want to know if i've missed something or if i should write patch.

Steps to reproduce
Try to upload a document.

Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes

πŸ› Bug report
Status

Closed: duplicate

Version

3.0

Component

Code

Created by

πŸ‡¬πŸ‡§United Kingdom Ben25

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

Comments & Activities

Production build 0.71.5 2024