I have stored jpeg files in the AppData Documents directory. Now I want to display the images. The images can be displayed in the html with
img src="{{image2}}"
based in part on josh morony ‘ionic capacitor photo save’, in part on capacitor source code FileSystem API) :
fileName1 = "photo2.jpeg";
Filesystem.getUri({
directory: FilesystemDirectory.Data,
path: fileName1
}).then((result) => {
this.image1 = result.uri.replace('file://', '_capacitor_');
}, (err) => {
console.log(err);
});
fileName2 = "photo2.jpeg";
Filesystem.getUri({
directory: FilesystemDirectory.Data,
path: fileName2
}).then((result) => {
this.image2 = result.uri.replace('file://', '_capacitor_');
}, (err) => {
console.log(err);
});
I would like to refactor the code, having the fileNames in an array [“photo1.jpeg”,“photo2.jpeg”] and get the path names [“this.image1”,“this.image2”] into an array.
I assume that I need a loop, and a Promise inside the loop with the result pushed into a new array. I would like some principle advice. Can I for exampel place the entire code ( FileSystem … into a array.push function ?