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!
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.