Managed File is stuck with a temporary URI, even after saving it as permanent file I was having this problem: Files uploaded via custom configuration form are eventually lost.

So, I used the solution, basically:

$file-&gt;setPermanent();
$file-&gt;save();


But then, even thou $file-&gt;isTemporary() is FALSE, the URI and URL seem to indicate that the file is still temporary:

URI: $file-&gt;getFileUri() yields temporary://filename.jpg

URL: file_create_url($file-&gt;getFileUri()) yields /system/temporary?file=filename.jpg
You need to mark file as "used", there is file.usage service for that, you can do it by next code: \Drupal::service('file.usage')-&gt;add($file), but after removing file from config or changing it by another file don't forget to remove file usage by \Drupal::service('file.usage')-&gt;delete($file), otherwise file would not be removed from file system.

In drupal 8.3 default behavior about unused files was changed and by default all unused files should not be deleted, until variable make_unused_managed_files_temporary is true.