blazor retrieving base64 string from js code which displays an image

i am using this js:

window.previewImage = (inputElem, imgElem) => {
    const url = URL.createObjectURL(inputElem.files[0]);
    imgElem.addEventListener('load', () => URL.revokeObjectURL(url), { once: true });
    imgElem.src = url;
}

with this razor file:

@inject IJSRuntime JS


<InputFile @ref="inputFile" OnChange="@ShowPreview" />
<img id="capturedImage" style="max-width:400px;max-height:400px" @ref="previewImageElem" />

    @code {
        private InputFile? inputFile;
        private ElementReference previewImageElem;
        private string base64Image = "";
    
    
        private async Task ShowPreview() => await JS.InvokeVoidAsync(
            "previewImage", inputFile!.Element, previewImageElem);
    
    
    }

this displays the images just fine, however in order to upload it to our server I need to be able to access the image from c# code and put it into a base64 string.

How can I achieve that?