refresh image after upload

Hi this is the code i’m trying to use to get latest upload shown in image placeholder. The code in green is the code snippet i’ve added

freeimageupload is the name of the uploading button, assigned in properties

freeViewPhoto is the name of the button which submits upload

image26 is the placeholder used to display the last image uploaded

export function freeimageupload_change_1(event) {
$w(‘#freeimageupload’).hide();
$w(‘#freeViewPhoto’).expand();
}

export function freeViewPhoto_click(event) {
$w(“#freeViewImageStrip”).show();
$w(‘#freeViewImageStrip’).scrollTo()
$w(‘#freeeditPhoto’).show();
if ($w(“#freeimageupload”).value.length > 0) {
$w(“#text1”).text = Uploading ${$w("#freeimageupload").value[0].name};
$w(“#freeimageupload”).startUpload()
.then( (uploadedFile) => {
wixData.insert(“image26”, uploadedFile).then(() => {
$w(“#image26”).refresh(); // this will refresh the gallery dataset ( you called it - upload folder - and shows all the images in that dataset.
});

        }) 

}

export function freeeditPhoto_click(event) {
$w(‘#freeUploadImageStrip’).scrollTo()
$w(‘#freeimageupload’).show();
$w(‘#freeViewPhoto’).collapse();

}

Thanks and Regards
Adam

https://www.wix.com/corvid/reference/wix-dataset.Dataset.html#refresh

Hi givemewhisky, thanks. I have added the following two snippets to see if that helps. The preview site still won’t show refreshed images. The collection / code only shows the previous image uploaded to the collection. A bit frustrating now because i think the code you linked me to should work

just a reminder. dataset1 is write and dataset 2 reads from the collection

$w.onReady( () => {
$w(“#dataset1”).onReady( () => {
$w(“#dataset1”).remove()
.then( () => {
console.log(“Done removing current item”);
} );

} );

} );
$w.onReady( () => {
$w(“#dataset2”).onReady( () => {
$w(“#dataset2”).refresh()
.then( () => {
console.log(“Done refreshing the dataset”);
} );

} );

} );

}

Thans and Regards
Adam

tried again with different code configuration

this is the error message i get


code

export function freeimageupload_change_1(event) {
$w(‘#freeimageupload’).hide();
$w(‘#freeViewPhoto’).expand();
$w.onReady( () => {
$w(“#dataset2”).onReady( () => {
$w(“#dataset2”).refresh()
.then( () => {
console.log(“Done refreshing the dataset”);
} );

} );

} );

}

export function freeViewPhoto_click(event) {
$w(“#freeViewImageStrip”).show();
$w(‘#freeViewImageStrip’).scrollTo()
$w(‘#image25’).show();
$w(‘#freeeditPhoto’).show();

}

export function freeeditPhoto_click(event) {
$w(‘#freeUploadImageStrip’).scrollTo()
$w(‘#freeimageupload’).show();
$w(‘#freeViewPhoto’).collapse();

}

If you can help that will be much appreciated
Thanks and Regards
Adam

Maybe i should be more specific to begin with

how to fix: the image failed to upload

and

save operation failed: dataset error. Operation cancelled by user code

where have i gone wrong?

Thanks and Regards
Adam

would a wix data query return the last uploaded image?

Could someone from wix please investigate my support ticket. Thanks Adam

I’m just looking for a definitive answer as to whether an image can be refreshed on the same page as as the upload button by using two different strips and a placeholder in the second strip?

The problem is that the the image shown when saved is not the image i’ve uploaded when selecting an edit image button link that takes me back to the upload button which starts the upload process again

Are there any forum moderators, ninjas or forum community members out there who can answer this please?