Add file field with Form API I'm writing a block plugin that uses the form API to allow users to edit its settings, and then output them into a template.

I'm currently using

&lt;?php

/**
 * @file
 * Contains \Drupal\my_plugins\Plugin\Block\InfoWithSideImage.
 */

namespace Drupal\my_plugins\Plugin\Block;

use Drupal\Core\Block\BlockBase;
use Drupal\Core\Form\FormStateInterface;

/**
 * @Block(
 * id = "infowithsideimage",
 * admin_label = @Translation("Info block beside an image")
 * )
 */

class InfoWithSideImage extends BlockBase {
    public function blockForm($form, FormStateInterface $form_state) {
        $form['image'] = array(
            '#type'          =&gt; 'file',
            '#title'         =&gt; $this-&gt;t('Image'),
            '#default_value' =&gt; $this-&gt;configuration['image_submit'],
        );
        $form['test'] = array(
            '#type' =&gt; 'textfield',
            '#title' =&gt; $this-&gt;t('Test text field'),
            '#default_value' =&gt; $this-&gt;configuration['test_submit'],                
        );
        return $form;
    }
    public function blockSubmit($form, FormStateInterface $form_state) {
        $this-&gt;configuration['image_submit'] = $form_state-&gt;getValue('image');
        $this-&gt;configuration['test_submit'] = $form_state-&gt;getValue('test');
    }

    public function build() {
        return array(
            '#theme' =&gt; 'infowithsideimage',
            '#image' =&gt; $this-&gt;configuration['image_submit'],
            '#test' =&gt; $this-&gt;configuration['test_submit'],
        );
    }
}


The text field works fine, but whenever I try to submit with the file field I get the following error:


  A fatal error occurred: Serialization of Symfony\Component\HttpFoundation\File\UploadedFile is not allowed


Is there something I'm missing? Is it possible to use the form API to allow users to upload files?
I discovered that the error only occurred when using the in-place panel editor. When adding the block in the panel page editor there were no errors.