Answers for "wait until onload finish JavaScript"

0

wait until onload finish JavaScript

const processFile = (file) => {
  const reader = new FileReader()

  return new Promise((resolve, reject) => {
  
    reader.onload = (fileEvent) => {
      const fileContents = fileEvent.target.result
      const processedContents = performPreprocessingOnFile(fileContents)
      resolve(processedContents)
    }
    reader.onerror = () => {
      reject('oops, something went wrong with the file reader.')
    }
    reader.readAsArrayBuffer(file)
  })
}

processFile(myFile).then((processedContents) => {
  fetch('https://my-backend-site/post-endopint', {
    method: 'POST',
    body: processedContents,
  })
})
Posted by: Guest on October-17-2021

Code answers related to "wait until onload finish JavaScript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language