I am using Moralis in my Angular 11 app and Iβm trying to add the functionality for user to add their user image. but when I add an image, I receive this error in my console:
core.js ERROR Error: Uncaught (in promise): Error: Tried to encode an unsaved file.
Error: Tried to encode an unsaved file.
This is my html:
<input
id="input__user--avatar"
#fileInput
type="file"
name="pic"
formControlName="avatar"
/>
and this is my typescript:
const uploadedFile = this.el.nativeElement;
if (uploadedFile.files.length > 0) {
const file = uploadedFile.files[0];
const name = 'avatar.jpg';
const avatar = new Moralis.File(name, file);
this.moralisService.changeAvatar(avatar);
}
This is changeAvatar method in Moralis service:
changeAvatar(avatar: any): void {
this.currentUser.set('avatar', avatar);
this.currentUser.save();
}