const uploadFunction = event => { const fileInput = event.target; const files = event.target.files const path = event.target.value; const allowedExtensions = ['jpg', 'png', 'gif']; const splitName = path.split('.'); const extenstion = splitName[splitName.length-1]; if (!allowedExtensions.include(extenstion)) { alert('Invalid file type'); fileInput.value = ''; return false; } const data = new FormData() data.append('file', files[0]) fetch('/upload-file', { method: 'POST', body: data }) .then(response => response.json()) .then(data => { console.log(data) }) .catch(error => { console.error(error) }) }