Upgrade Your Drupal Skills

We trained 1,000+ Drupal Developers over the last decade.

See Advanced Courses NAH, I know Enough

Uploading big files to Drupal 8: PLUpload integration

Parent Feed: 

As of this writing the only site building readily available module is the PLUpload file widget.

This module depends on the PLUpload form element provided by the Plupload integration module, that is a more developer oriented module.

With the Plupload widget/integration you can:

  • Have a drop-in replacement for core's file widget that supports big uploads (HTML 5 based)
  • Have a powerful FAPI element to upload big files

What kind of things can you do with this? See this video from our "Powerpoint to Files" post where a user uploads a several hundred megabytes Powerpoint file that gets converted to high quality images on the server side:

Once you have deployed the Plupload integration module you can use the FAPI widget to add uploading capabilities with code like this:

  /**
   * {@inheritdoc}
   */
  public function form(array $form, FormStateInterface $form_state) {
    $form = parent::form($form, $form_state);
    $form = Form::Instance('', $form);

    $form->AddElement('slides', [
      '#type' => 'plupload',
      '#title' => t('Cargar archivos'),
      '#autoupload' => TRUE,
      '#autosubmit' => TRUE,
      '#description' => t('Suba aquí los archivos de slides que se adjuntaran a la presentación.'),
      '#submit_element' => '#slides-upload',
      '#upload_validators' => [
        'file_validate_extensions' => ['zip ppt pptx'],
      ],
      '#plupload_settings' => [
        'runtimes' => 'html5,html4',
        'unique_names' => TRUE,
        'max_file_size' => static::MAX_FILESIZE_UPLOAD,
        'chunk_size' => '1mb',
      ],
    ]);

    $form = $form->Render();

    return $form;
  }

To use the site building capabilities of the Plupload File widget you simply pick the Plupload widget:

After that you will be presented with a Plupload widget to upload very big files comfortably;

What is important about this module is the fact that it is an extremely simple drop-in replacement for the core File widget. Indeed, most of the logic is inherited from the core File widget, making it future proof with very little maintenance.

Author: 
Original Post: 

About Drupal Sun

Drupal Sun is an Evolving Web project. It allows you to:

  • Do full-text search on all the articles in Drupal Planet (thanks to Apache Solr)
  • Facet based on tags, author, or feed
  • Flip through articles quickly (with j/k or arrow keys) to find what you're interested in
  • View the entire article text inline, or in the context of the site where it was created

See the blog post at Evolving Web

Evolving Web