Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const file = document.querySelector('#file')
- function upload(file){
- fetch('https://www.example.com', { // // Your POST endpoint
- method: 'POST',
- headers: {
- "Content-Type": "image/png" // specify your content type (json or text or imge - look at google how to specify your content according to your data type)
- },
- body: file // your file object to be passed
- })
- .then(response => console.log(response.json)) // if the response is json object
- .then(success => console.log(success)) // return success response if request is sucessfull
- .catch(error => console.log('An error occurred: ', error)) // listen for error occurring...
- }
- const startUpload = () => upload(file.files[0]);
- file.addEventListener('change', startUpload, true);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement