How can I upload files with the form element type file?
I had the same problem with the file form element. Solved this by using managed_file and providing the upload location and validators in the form element:

$form['test_CERTIFICATE'] = [
  '#type' =&gt; 'managed_file',
  '#title' =&gt; $this-&gt;t('Certificate'),
  '#upload_location' =&gt; 'private://certfiles',
  '#upload_validators' =&gt; [
    'file_validate_extensions' =&gt; ['pem'],
  ],
];


Then in submit:

use Drupal\file\Entity\File;

$form_file = $form_state-&gt;getValue('test_CERTIFICATE', 0);
if (isset($form_file[0]) &amp;&amp; !empty($form_file[0])) {
  $file = File::load($form_file[0]);
  $file-&gt;setPermanent();
  $file-&gt;save();
}