Most in general this is it, I have some signal based code (Angular) that I set the state to when the event fires.
/**
* Registers Uppy instance
*/
registerUppy({ allowedFileTypes, meta }: UppyOptions): void {
this.uppy = new Uppy<Meta>({
autoProceed: true,
restrictions: {
allowedFileTypes,
},
meta,
});
this.$uploadState.update(currentState => ({
...currentState,
progress: 0,
files: {},
}));
if (this.uppy) {
this.configureUppy(this.uppy);
}
}
/**
* Configures Uppy instance
*/
configureUppy(uppy: Uppy): void {
const msalAccount = this.authenticationService.getActiveMSALAccount();
const windowsAccount = this.authenticationService.getActiveWindowsAccount();
if (msalAccount) {
let accessToken = '';
this.msalService
.acquireTokenSilent({
scopes: environment.apiConfig.scopes,
account: msalAccount,
})
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(accountInfo => {
accessToken = accountInfo.accessToken;
uppy.use(Tus, {
endpoint: environment.apiConfig.uri.split('/api')[0] + '/upload',
headers: {
Authorization: `Bearer ${accessToken}`,
},
});
});
} else if (windowsAccount) {
uppy.use(Tus, {
endpoint: environment.apiConfig.uri.split('/api')[0] + '/upload',
withCredentials: true,
});
}
/**
* Upon a file restriction failure
*/
uppy.on('restriction-failed', (file, error) => {
// TODO: Remove notification if unnecessary
if (file) {
this.toastsService.showErrorToast(
`Adding file ${file.name} failed. Error: ${error.message}`,
);
}
});
There isn’t much else configuration wise. This restriction failed is just an example of an event handling.