FileInterface EXISTS_REPLACE is deprecated in Drupal 10

When saving files in Drupal 10 I encountered this deprecation error: 

    $file = \Drupal::service('file.repository')->writeData($binaryimg, $file_path, FileSystemInterface::EXISTS_REPLACE);
@deprecated in
drupal:10.3.0 and is removed from drupal:12.0.0. Use \Drupal\Core\File\FileExists::Rename instead.

Solution

use Drupal\Core\File\FileExists;

$file = \Drupal::service('file.repository')->writeData($binaryimg, $file_path, FileExists::Rename);

 

 

Saved you some valuable time?

Buy me a drink 🍺 to keep me motivated to create free content like this!