I have integrated a file upload feature into my web application, allowing users to upload images, .doc, .docx, and pdf files.
Currently, I am facing an issue with converting the file contents into a byte[] array to send it to my API for storage.
Although I attempted to convert from ArrayBuffer to Uint8Array, I encountered challenges and have not succeeded in resolving the issue.
Below is the snippet of code where I read the file and gather the necessary information:
Any assistance or guidance on this matter would be greatly appreciated.
let myFile = ev.target.files[0];
if(myFile.size > 0){
let reader = new FileReader();
var fileByteArray = [];
reader.readAsArrayBuffer(myFile);
reader.onloadend = (ev) => {
var uintArray = new Uint8Array(reader.result.toString().length);
//var arrayBuffer = new ArrayBuffer(reader.result);
//var array = new Uint8Array(arrayBuffer);
let resourceModel = new AddForumThreadResourceRequestModel({
contentType: myFile.type,
fileName: myFile.name,
fileContent: uintArray
});
console.log(resourceModel);
this.forumApi.AddThreadResource(resourceModel).subscribe(
data => {
if(data != null || data == true){
this.errorCtrl.presentToast("New resource has been added to the thread");
}
});
}
}