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 Uploader add list of necessary events #5143

Open
2 tasks done
MaxAndDev opened this issue May 3, 2024 · 0 comments
Open
2 tasks done

Custom Uploader add list of necessary events #5143

MaxAndDev opened this issue May 3, 2024 · 0 comments

Comments

@MaxAndDev
Copy link

Initial checklist

  • I understand this is a feature request and questions should be posted in the Community Forum
  • I searched issues and couldn’t find anything (or linked relevant results below)

Problem

There is a problem with the documentation when creating custom uploader plugins. It does not outline that this event

this.uppy.emit('upload-start', this.uppy.getFiles())

is needed to make Uppy show any progress or to get to the "Done" state.

Solution

Simply add a list of events that are needed to the docs. I mean ya we could also visit the implementation of the TUS uploader but it would be nice to have everything together in one place. Essential events that are needed for custom uploader are

'upload-start' with a list of uppy files
'upload-success' for each successfully uploaded file
'upload-error' for each failed upload

and then the progress events, but those are outlined in the docs 🙏

upload(fileIDs: string[]) {
    // emit the event for progress tracking to uppy
    this.uppy.emit('upload-start', this.uppy.getFiles())

    const promises = fileIDs.map((fileId) => {
      const file = this.uppy.getFile(fileId)

      return new Promise((resolve, rejects) => {
      // some upload hook
        this.uploadHook(file.data)
          .then((result: any) => {
            // event emitting is important for uppy to keep track of the actual progress state
            this.uppy.emit('upload-success', file, result)
            resolve(result)
          })
          .catch((err: any) => {
            // event emitting is important for uppy to keep track of the actual progress state
            this.uppy.emit('upload-error', file, err)
            rejects(err)
          })
      })
    })

    return Promise.all(promises).then(() => {}) // returned promise needs to be Promise<void>
  }

Alternatives

Just link to the TUS implementation for a "custom" uploader example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants