Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom File Storage Error Unhandled #412

Open
arturo-switchboard opened this issue Jul 11, 2024 · 0 comments
Open

Custom File Storage Error Unhandled #412

arturo-switchboard opened this issue Jul 11, 2024 · 0 comments

Comments

@arturo-switchboard
Copy link

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 })
  })
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant