How can I convert a uploaded file to byte array in Angular/Typescript?
Component.ts
buildRequest(): CreateRequest {
var reader = new FileReader();
return {
create: {
fileData: this.reader.readAsArrayBuffer(this.fileToUpload)
}
};
}
Model
export interface CreateRequest {
create: {
fileData: Uint8Array[]; // Also, is this correct representation of byte array?
};
}
Currently, I am getting an error when I am assigning ReadAsArrayBuffer
function to fileData -
"Type 'void' is not assignable to type 'Uint8Array[]'"
.
What is the correct way of sending byte array to API request?