Sideloading an image from a function in a plugin I need to be able to side load an image and attach to an entry.

My image is coming from an external url... such as http://someplace.com/image.jpg - i can store this in a temporary file so its locally accessible.  But then how do I upload this image (without using $_POST or $_FILES) and attach to an entry.

The method i'm trying at the moment i'm using something like:
uploadNewAsset(UploadedFile $uploadedFile, $folderId)

But UploadedFile seems to only want to accept POST variables, unless i'm missing something

Any help would be great

Thanks
You can see an entire example how to fetch a file via curl, save it into an asset and relate it to an entry here

// get the entries service
$entries = Craft::$app-&gt;getElements();

// get the entry
$entry = \craft\elements\Entry::find()-&gt;one();

// somehow grab the path of your image
$client = Craft::createGuzzleClient();
$response = $client-&gt;get('https://www.google.com/logos/2018/halloween18/rc5/cta.png');

$image = $response-&gt;getBody()-&gt;getContents();
$path = Craft::$app-&gt;getPath()-&gt;getTempPath() . DIRECTORY_SEPARATOR  . 'someFile.png';
FileHelper::writeToFile($path, $image);

// the folder for the image
$folder = Craft::$app-&gt;getAssets()-&gt;getFolderById(1);

// create a new asset
$asset = new \craft\elements\Asset();
$asset-&gt;tempFilePath = $path;
$asset-&gt;filename = 'someFileName.jpg';
$asset-&gt;title = 'someTitle';
$asset-&gt;newFolderId = $folder-&gt;id;
$asset-&gt;volumeId = $folder-&gt;volumeId;
$asset-&gt;avoidFilenameConflicts = true;
$asset-&gt;setScenario(\craft\elements\Asset::SCENARIO_CREATE);
if($entries-&gt;saveElement($asset) === true){
    // file was saved 
    $entry-&gt;setFieldValue('assetFieldHandle', [$asset-&gt;id]);
    $entries-&gt;saveElement($entry);
}