Is there any way to replace the asset programatically? In the CP, when we upload an image with a same name, craft will ask if we wanna keep both or replace.
So in plugin, is there any way to do the replace?
You need to set the scenario SCENARIO_REPLACE or SCENARIO_CREATE depending what you like to do

$asset = new \craft\elements\Asset();
$asset-&gt;tempFilePath = $tmpFilePath;

$asset-&gt;setScenario(\craft\elements\Asset::SCENARIO_REPLACE);