Unable to downloaded the file mobile device using Cordova plugin file


#1

Ionic version:
Ionic Framework Version: 3.0.1

I have created a sample app to download a file in Mobile device
but when I click on download button, I see the download succeeded meessage. But image
does not appear in my image gallery .

Current behavior:
Image is not appearing in gallery.

Expected behavior:
Downloaded image should appear in gallery.

Steps to reproduce:
Install the app in android phone and click on download button.

Related code:
Type Script Code
"
import {Component} from ‘@angular/core’;
import {NavController, Platform, AlertController} from ‘ionic-angular’;
import {Transfer, TransferObject} from ‘@ionic-native/transfer’;
import {File} from ‘@ionic-native/file’;

@Component({
selector: ‘page-home’,
templateUrl: ‘home.html’,
providers: [Transfer, TransferObject, File]
})

export class HomePage {

storageDirectory: string = ‘’;

constructor(public navCtrl: NavController, public platform: Platform, private transfer: Transfer, private file: File, public alertCtrl: AlertController) {
this.platform.ready().then(() => {
// make sure this is on a device, not an emulation (e.g. chrome tools device mode)
if(!this.platform.is(‘cordova’)) {
return false;
}

if (this.platform.is(‘ios’)) {
this.storageDirectory = cordova.file.documentsDirectory;
}
else if(this.platform.is(‘android’)) {
this.storageDirectory = cordova.file.dataDirectory;
}
else {
// exit otherwise, but you could add further types here e.g. Windows
return false;
}
});
}

downloadImage(image) {

this.platform.ready().then(() => {

const fileTransfer: TransferObject = this.transfer.create();

const imageLocation = ${cordova.file.applicationDirectory}www/assets/img/${image};

fileTransfer.download(imageLocation, this.storageDirectory + image).then((entry) => {

const alertSuccess = this.alertCtrl.create({
  title: `Download Succeeded!`,
  subTitle: `${image} was successfully downloaded to: ${entry.toURL()}`,
  buttons: ['Ok']
});

alertSuccess.present();

}, (error) => {

const alertFailure = this.alertCtrl.create({
  title: `Download Failed!`,
  subTitle: `${image} was not successfully downloaded. Error code: ${error.code}`,
  buttons: ['Ok']
});

alertFailure.present();

});

});
}

retrieveImage(image) {

this.file.checkFile(this.storageDirectory, image)
.then(() => {

const alertSuccess = this.alertCtrl.create({
  title: `File retrieval Succeeded!`,
  subTitle: `${image} was successfully retrieved from: ${this.storageDirectory}`,
  buttons: ['Ok']
});

return alertSuccess.present();

})
.catch((err) => {

const alertFailure = this.alertCtrl.create({
  title: `File retrieval Failed!`,
  subTitle: `${image} was not successfully retrieved. Error Code: ${err.code}`,
  buttons: ['Ok']
});

return alertFailure.present();

});
}

}"


#2

Please use the </> button above the post input field to format your code or error message or wrap it in ``` (“code fences”) manually. This will make sure your text is readable and if it recognizes the programming language it also automatically adds code syntax highlighting. Thanks.


#3

check in the internal memory in android folder within your application name folder


#4

@vks_gautam1 I have checked many times and I do not find the file. Though its an image and should appear in image gallery as well. Please suggest if the code is right? I am using xiomi mi3 android device


#5

i think your need to add .jpg as well in “download path” with image


#6

@vks_gautam1 checked with same. But I don’t see the file :frowning: