Network request shows that the images are returning to frontend (ANGULAR 13) from NestJs server, but the type is text/html
with 200 status and initiator:platform-broweser.mjs
. There is no error on console.The image path is stored in MongoDb and path is attached with product.I want to convert that text/html response into actual image that is uploaded to server and make the images visible as the products with details are visible but images are not visible.'
Here Showing all the products
BookForm = new FormGroup({
_id: new FormControl(''),
name: new FormControl(''),
author: new FormControl(''),
price: new FormControl(''),
genres_name: new FormControl(''),
coverimage: new FormControl(''),
});
results?: Book[];
constructor(
private readonly apiService: ApiService,
private router: Router,
) {}
ngOnInit() {
this.apiService.getallbooks().subscribe((data: Book[]) => {
this.results = data;
});
}
Showing All products html
<div class="grid" *ngFor="let result of results">
<div class="blog-card spring-fever" style="padding: 0.5rem; z-index: 100">
<img
class="image"
src="http://localhost:3000/{{ result.coverimage }}"
alt=""
height="400px"
width="250px"
style="border: 1px solid red"
/>
Angular file upload encoded base64
imagedata?: string;
async uploadimage(event: any) {
const file = event.target.files[0];
this.AddbookForm.patchValue({ coverimage: file });
const allowedMimeTypes = ['image/png', 'image/jpeg', 'image/jpg'];
this.AddbookForm.get('coverimage')?.updateValueAndValidity();
if (file && allowedMimeTypes.includes(file.type)) {
const reader = new FileReader();
reader.onload = () => {
this.imagedata = reader.result as string;
};
reader.readAsDataURL(file);
console.log(file);
}
}