S3 Multipart - Preauthorization API request prior to upload?

Hello! I’ve got the S3 Multipart plugin in Uppy v3 (3.whatever latest is) communicating nicely with a Next.js API. Everything works right perfectly right now but I want to perform a request prior to the upload that, if successful, will create a row in a DB and return a key that subsequent requests should reference throughout the process. So it should look like this:

  • User selects file for upload
  • File metadata is sent to server
  • If authorized, server inserts row into table and responds with Id
  • ID is added as meta to subsequent requests

From what I can tell, the way to do this would be through a custom middleware in the client that extends the BasePlugin class. Is that correct? This seems like a pretty typical workflow, any chance there’s some simple existing plugin or support for it that doesn’t require a new middleware?

Appreciate your help! I used Uppy a few years ago on another project with great success. It’s refreshing to see you’re still killin’ it. Thanks for your work!

Hi!
What about the file-added event in Uppy? Uppy — Uppy

Then you can send a request to the server, and on response, you can call setMeta with the response from the server Uppy — Uppy

then this meta will be added to the upload

Hey, thanks for checking this out!

Do you know if this approach supports async events? This would need to cancel the upload if the preauth request fails. The docs make it seem like this isn’t the spot for that.

I hacked out a plugin last night that did the trick. I’ll post it here for reference when I next sit down.

Unfortunately I don’t think there is any supported way to easily do this asynchronously while locking the UI with a loader/spinner so the user doesn’t do anything while the request is ongoing. The Uppy team will discuss whether it makes sense to add some built in functionality for this

Yeah, that was the impression I got from the docs. It does seem extremely likely that this is a very common use case: pre-auth prior to upload, finalize on completion. A dedicated callback could be added to Uppy that requires a promise to successfully resolve in order to continue. The preprocessing stage available to plugins seems to already expose this exact behavior. A shortcut to add a one-off async callback doesn’t seem like too heavy of a lift.

Oh actually after talking to the Uppy Oracle, I noticed that we do have a disabled option that can be used to disable the UI: Dashboard — Uppy

So I think you could use this to disable the UI until you have your response, then set the metadata.

Although I agree it would make sense to have such a preauth option too, we’ll discuss it, thanks.