Files uploaded via custom configuration form are eventually lost This is a difficult one to explain. so, I am hoping that someone else has had a similar problem. I am uploading a file via custom configuration form, my field on the form looks like:

$form['homepage_image'] = array(
  '#type' =&gt; 'managed_file',
  '#description' =&gt; t('The image used on the home, agents, and featured property pages.'),
  '#default_value' =&gt; $config-&gt;get('pm_admin.homepage_image'),
  '#upload_location' =&gt; 'public://upload/siteimages',
  '#required' =&gt; TRUE,
);


My submit handler sets the config property in the bog standard way:

$config-&gt;set('pm_admin.homepage_image', $form_state-&gt;getValue('homepage_image'));


Initially this all works fine, the image is saved and I can grab it and render it where I want in templates. However, after several hours (I have not figured out the trigger) the image disappears. The configuration form no longer has the value. The file is also removed from the file system. 

Not sure what is causing this and would appreciate any help.
The trigger is the 'status' property of the file. It defaults to temporary, and Drupal clears out temporary managed files on a cron run.

To fix, add this to your form's submit method:

$fid = $form_state-&gt;getValue('homepage_image')[0];
$file = \Drupal\file\Entity\File::load($fid);
$file-&gt;setPermanent();
$file-&gt;save();