top of page
bottom of page
import wixData from 'wix-data'; export function button1_click(event) { let file = $w("#uploadButton").value[0]; let url = await uploadFile(file); let memberId = wixUsers.currentUser.id; wixData.get("Members", memberId) .then((member) => { member.profilePhoto = url; return member.save(); }) .catch((err) => { console.log(err); }); } function uploadFile(file) { return new Promise((resolve, reject) => { let name = file.name; let type = file.type; let size = file.size; wixData.getUploadUrl() .then((uploadUrl) => { return fetch(uploadUrl, { method: "PUT", headers: { "Content-Type": type, "Content-Length": size }, body: file }); }) .then((response) => { if (response.ok) { resolve(name); } else { reject(response.statusText); } }) .catch((err) => { reject(err); }); }); }