I'm trying to display images that their URLs comes from Flickr photo search API. I want to convert these image URLs to base64 so I can store the images in Session Storage and only call Flickr API if images do not exist in Session Storage:
export class AComponent {
results: any[];
base64;
constructor(private http: HttpClient, private jsonp: Jsonp, private router: Router,
private storage: SessionStorageService) {
if (!sessionStorage.getItem("results")) {
this.http.get('https://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=378060923d01ccb122bd53491163355d&tags=jungle&per_page=5&format=json&nojsoncallback=1').subscribe(data => {
this.results = (<RootObject>data).photos.photo.map((photo) => {
return {
// url:`https://farm${photo.farm}.staticflickr.com/${photo.server}/${photo.id}_${photo.secret}_m.jpg`,
base64: this.base64, // this line how can I get base64 image from the above url
title: photo.title
}
});
sessionStorage.setItem("results", JSON.stringify(this.results));
});
}
else {
this.results = JSON.parse(sessionStorage.getItem("results"))
}
}
}