Tus-js-client multiple uploads - how to tell them apart on success

Hello,

I’m working on a web app that allows uploading multiple files from one form/page. My plan is to start all the uploads when the form is submitted by the user, then as each upload completes, do some bookkeeping for each one, and when all of them are complete submit the form to the web application.

My problem is that in the upload onSuccess callback there does not seem to be any way of knowing for which upload the function is being called. I suppose I can figure out somehow which of the uploads have completed when the callback is invoked, but I would probably end up doing the bookkeeping multiple times unless I know which one just completed.

Is there some way of handling this scenario? I’m probably missing something, but I can’t find anything in the documentation.

Thanks for any help you can give me, and thanks for making the protocol and client available to the public!

P.S. I’m using the 3.1.0 version of tus-js-client.

You could bind your onSuccess callback to an identifier for the file and identify the uploads that way. The bound callback is then passed in the options to tus.Upload:

function onSuccess(file) {
  console.log(`File ${file.name} is uploaded`)
}

files.forEach((file) => {
  const upload = new tus.Upload({
     endpooint: ...,
     onSuccess: onSuccess.bind(null, file)
  })

  upload.start()
}

Thank you very much!