I need to dowload and cache images in my app, and I was able to achieve that but because of cors issues I had to use the http plugin from capacitor comunity. The problem is that the downloadFile() function does not seems to save the download image in cache folder, it dowload the image but it does not save in cache. When I try to read the saved image I get an error saying that the file does not exist. Also looking into applicaton FileStorage in devtools i can not find the image.
What could be wrong?
async cacheImage(url) {
const imageName = url.split('/').pop();
const options: HttpDownloadFileOptions = {
url: url,
filePath: imageName,
fileDirectory: Directory.Cache
};
const response = await Http.downloadFile(options);
console.log(response); // this is working fine I get a blob file
Filesystem.readFile({
directory: Directory.Cache,
path: imageName,
})
.then((file) => {
this.imgSrc= file;
})
.catch((err) => {
//This error is shown.
console.error('error', err);
})
}
1 post - 1 participant