Dealing with the challenge of uploading files in mp4 and jpg formats, I have set up 2 separate instances of FileUploader with custom validation. Upon clicking the upload button, I attempt to merge the files from both instances into a single FileUploader and trigger the upload all method to send the files to the server (API Service). However, I am encountering an issue where the server is not being hit. Below is the code snippet outlining my attempts to resolve this problem - any assistance would be greatly appreciated.
File Uploader Initialization
uploader: FileUploader;
coverImageUploader: FileUploader;
mergedFileUploader: FileUploader;
options: FileUploaderOptions = {
url: URL,
authToken: `Bearer Token`,
authTokenHeader: 'authorization',
isHTML5: true,
method: 'POST',
itemAlias: 'file',
headers: [{
name: 'refId',
value: ''
}, {
name: 'userId',
value: ''
}, {
name: 'roleId',
value: ''
}]
}
this.uploader = new FileUploader(this.options);
this.coverImageUploader = new FileUploader(this.options);
this.mergedFileUploader = new FileUploader(this.options);
Combining Files from Multiple FileUploaders
let files: any = []
files.push(this.uploader.getNotUploadedItems().filter((f: FileItem) => !f.isUploading))
files.push(this.coverImageUploader.getNotUploadedItems().filter((f: FileItem) =>
!f.isUploading))
var merged = [].concat.apply([], files);
merged.forEach(e => {
e.options.headers.find((o, i) => {
if (o.name === 'refId') {
e.options.headers[i] = {
name: 'refId',
value: e.formData.reduce(r => r).RefId
};
return true;
} else if (o.name === 'userId') {
e.options.headers[i] = {
name: 'userId',
value: user.userId.toString()
};
return true;
} else if (o.name === 'roleId') {
e.options.headers[i] = {
name: 'userId',
value: user.roleId.toString()
};
return true;
}
})
})
this.uploader.clearQueue();
this.coverImageUploader.clearQueue();
this.mergedFileUploader.clearQueue()
this.isUploadProcessing = true
this.mergedFileUploader.addToQueue(files)
Handling Upload Button Click Event
UploadFiles(){
this.mergedFileUploader.uploadAll()
}