Save files to device storage ionic


#1

Hi,

I want to save files to device storage and display them back in UI. Can anyone help me out with this ?


#2

what kind of “files”? .txt or .doc?


#3

Basically anything, It can be .txt, .doc or even .pdf


#4

See https://ionicframework.com/docs/native/file/. If you are deploying to iOS and android be aware that some directories are not available on all plattforms.
From your application you could scan this directory or even save the file metadata to a localStorage.


#5

Not sure whether this is the right way to do. But I did something like this

Blockquote
let reader = new FileReader();
let filesrc;
reader.onload = function (loaded) {
filesrc = loaded.target.result;
context.fileTransfer.download(filesrc, context.file.externalRootDirectory + file.name).then(success => {
console.log(“File Copied” + context.file.externalRootDirectory);
context.file = context.file.externalRootDirectory + file.name;
}, error => {
console.log(error);
});
};