How to create an 'Upload a file' field?
$form['File'] = array(
        '#type' =&gt; 'managed_file',
        '#title' =&gt; t('Choose  File'),
        '#upload_location' =&gt; 'public://MyFilesFolder/',
        '#default_value' =&gt; $entity-&gt;get('File')-&gt;value,
        '#description' =&gt; t('upload file'),
        '#states' =&gt; array(
          'visible' =&gt; array(
            ':input[name="File_type"]' =&gt; array('value' =&gt; t('Upload Your File')),
          ),
        ),
      );