unlayer / react-email-editor

Drag-n-Drop Email Editor Component for React.js
https://unlayer.com/embed
MIT License
4.51k stars 728 forks source link

Custom File Storage Error Unhandled #412

Open arturo-switchboard opened 1 month ago

arturo-switchboard commented 1 month ago

The current sample for custom file storage results in an Unhandled Runtime Error. https://docs.unlayer.com/docs/custom-file-storage

image

Ideally I would like to be able to do something like:

unlayer.registerCallback('image', function(file, done) {
  var data = new FormData()
  data.append('file', file.attachments[0])

  fetch('/uploads', {
    method: 'POST',
    headers: {
      'Accept': 'application/json'
    },
    body: data
  }).then(response => {
    // Make sure the response was valid
    if (response.status >= 200 && response.status < 300) {
      return response
    } else {
      // Custom Logic on messaging (eg. toast)
      done({progress: 100})
    }
  }).then(response => {
    return response.json()
  }).then(data => {
    // Pass the URL back to Unlayer to mark this upload as completed
    done({ progress: 100, url: data.filelink })
  })
})