Here I set the function toBase64()
export function toBase64(file:File) {
return new Promise((resolve,reject)=>{
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onload=()=> resolve(reader.result);
reader.onerror=(error) =>reject(error);
})
it shows that the type of reader.result is
string | ArrayBuffer | null, however, when I need to use the response.
export class InputImgComponent implements OnInit {
constructor() { }
imageBase64!:string;
@Output()
onImageSelected = new EventEmitter<File>();
ngOnInit(): void {
}
change(event:any){
if(event.target.files.length>0) {
const file:File= event.target.files[0];
toBase64(file).then((value)=>this.imageBase64=value );
}
it said the result type is unknown, and I set imageBase64 to string, Type 'unknown' is not assignable to type 'string'.
That's really weird, how can I solve this problem, I only need the string result.