Hello-
Basically I’m trying to limit the number of images that a single user can upload in a single session (let’s say 2). I know I need to use session from wix-storage, but as I’m not heavy on coding, I couldn’t make it right.
Currently an upload to a ‘Wix Pro Gallery’ is being made via an ‘upload button’ and a ‘button’ which inserts the single uploaded image into a Dataset. Any idea how the combination between session and ’ databaseNumberOfImages ’ works within my code?
After researching in the forum, I believe that I need to add this function code (or similar) into my code:
This is the code which needs I need help in editing:
Import { session } from ‘wix-storage’;
session.setItem(“key”, “value”)
let databaseNumberOfImages = 2;
if (items.length >= databaseNumberOfImages) {
$w(" #uploadButton ").disable();
Here’s the part of my (working) code, which handles the upload, and which I’d need to add the new code above into:
import wixData from ‘wix-data’;
export function checkbox1_change(event, $w) { //ensures T&Cs box is ticked, otherwise ‘Upload’ button is disabled.
if ($w(“#checkbox1”).checked=== true ){
$w(“#button1”).enable();
$w(“#dataset1”).setFieldValue(“agreedTCs”, true );
$w(“#dataset1”).save();
}
if ($w(“#checkbox1”).checked=== false ){
$w(“#button1”).disable();
}
}
export function button1_click_1(event) { //Upload button to select a photo
if ($w(“#uploadButton1”).value.length > 0) {
$w(“#text19”).text = Uploading ${$w("#uploadButton1").value[0].name}
;
setTimeout( function () {
// $w(“#text19”).text = “Almost there… "
});
$w(”#uploadButton1").startUpload()
.then( (uploadedFile) => {
$w(“#text19”).text = “Upload successful”;
let toInsert = {
“MyPhoto”: uploadedFile.url
};
wixData.insert(“DD”, toInsert)
//Inserting the uploaded photo into the DB
.then( (results) => {
let item = results;
}).then(()=>{
$w(“#dataset1”).refresh();
});
})
. catch ( (uploadError) => {
$w(“#text19”).text = “File upload error”;
console.log(File upload error: ${uploadError.errorCode}
);
console.log(uploadError.errorDescription);
} );
}
}
Thanks for you help all.