UTNGYPisal
UTNGYPisal

Reputation: 61

Ionic2: get image form URL and save to native storage

Let's say I have a JSON object containing users' profile including firstname, lastname,..., and profileUrl from a web API. I've already saved the text data using Sqlite, and now I want to save those images in native storage and put the file path into the sqlite database replacing the profileUrl.

Upvotes: 1

Views: 455

Answers (1)

Andreas Gassmann
Andreas Gassmann

Reputation: 6544

You can use cordova-plugin-file-transfer for that. There is even an Ionic Native wrapper available: https://ionicframework.com/docs/native/transfer/

Example:

download() {
  const url = 'http://www.example.com/file.pdf';
  fileTransfer.download(url, this.file.dataDirectory + 'file.pdf').then((entry) => {
    console.log('download complete: ' + entry.toURL());
  }, (error) => {
    // handle error
  });
}

Upvotes: 2

Related Questions