Help! Tricky upload and refresh!

Hi forum!

I want to upload an image and refresh dataset as soon as this is done. Except, it only refreshes whenever it wants. Sometimes it does, sometimes it doesn’t and I end up not seeing the freshly uploaded photo

export function uploadButton1_change(event) {
$w(" #uploadButton1").startUpload().then((uploadedFile) => {
let toInsert = {
“title”: $w(“#text23”).text,
“image”: uploadedFile.url,
};
wixData.insert(“Portfolio”, toInsert)
.then(() => {
$w(‘#dataset2’).refresh( );
});
});
}