Fetch API upload function

const uploadFunction = event => {
  const files = event.target.files
  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)
  })
}