javascript
Published on January 26, 2024By DeveloperBreeze
// Get the file input element
const fileInput = document.querySelector('#file-input');
// Add an event listener for the 'change' event on the file input
fileInput.addEventListener('change', (event) => {
// Get the selected file
const file = event.target.files[0];
// Create a FormData object and append the file to it
const formData = new FormData();
formData.append('file', file);
// Use the Fetch API to send a POST request with the file data
fetch('/upload', { method: 'POST', body: formData });
});
Comments
Please log in to leave a comment.