Uploaded image in Block Plugin keeps on getting deleted overnight I have a block plugin that allows users to upload an image to be used as a background. Below is what is inside my blockForm function.

    $form = [
        'image' =&gt; [
            '#type' =&gt; 'managed_file',
            '#title' =&gt; 'Image',
            '#upload_location' =&gt; 'public://my_style/images',
            '#default_value' =&gt; $this-&gt;configuration['image'],
        ],
    ];


And my block submit function is as follows.

public function blockSubmit($form, FormStateInterface $form_state) {
    $values = $form_state-&gt;getValues();

    foreach ($values as $index =&gt; $value) {
        $this-&gt;configuration[$index] = $value;
    }
}


Initially this works just fine. The image is uploaded and appears in the background of my block plugin. However overnight it's always deleted. I did see this post Set image as permanent in custom block plugin, temporary URI however I don't see anything different that would cause issues with my code against the one provided in that post. Is there something missing? Or is there anything wrong with how I'm performing the submit function.

I suppose I could try to check if the formstate value is a file and then load the file and then set it to permanent and then save it. But even if that works why would it be necessary in this case but not in others?
As you guessed its must to set permanent while saving the file. You need to include,
    $file = File::load( $fid );
    if ($file) {
      $file->setPermanent();
      $file->save();
    }


  The files will be added to the {file_managed} table as temporary
  files. Temporary files are periodically cleaned. Use the 'file.usage'
  service to register the usage of the file which will automatically
  mark it as permanent.