Filesize getting compressed down to half while uploading using plupload

Created on 20 May 2024, 6 months ago
Updated 1 June 2024, 6 months ago

Problem

I am using plupload and plupload_widget modules with my Drupal 10 setup.
I am using this widget for video files like mp4. My system also uses AWS S3 bucket to store the files.
Field is added via custom code like:

$form['upload_video'] = [
      '#type' => 'plupload',
      '#title' => $this->t('File'),
      '#size' => 20,
      '#autoupload' => TRUE,
      '#autosubmit' => FALSE,
      '#multiple' => FALSE,
      '#accept' => 'video/*',
      '#required' => TRUE,
      '#upload_validators' => $validators,
      '#plupload_settings' => [
        'runtimes' => 'html5,flash,silverlight,html4',
        'chunk_size' => '1mb',
      ],
      '#upload_location' => 'public://',
    ];

In an ajax callback:

  • After uploading the file I am moving it from tmppath to the destination.
  • After moving the file successfully I am using the file_uri to create a new file, setting it to permanent and saving it.

The whole process is working fine step by step, already debugged on each step.

Now the issue is that the size of the file uploaded & saved is getting chopped to half after I upload a file using plupload.
Actual size shown on a widget is correct but the size after upload and save is half.

For Eg: If I upload 9.4MB file it chops down the size to be 3MB, 4.38MB or sometimes to 5MB and sometimes it is uploading the correct size which is 9.38MB (rarely). Its not consistent.


Tried multiple solutions around this:

  • Tried using different functions instead of move() from filesystem like copy(), prepareDirectory()
  • Tried using different PHP functions instead of move() from filesystem like copy(), unlink(), rename(), move_uploaded_file()

Nothing seems to work. Any type of help would be appreciated.

🐛 Bug report
Status

Closed: works as designed

Version

2.1

Component

Code

Created by

🇮🇳India Anul Delhi

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

Comments & Activities

Production build 0.71.5 2024