Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70763

Ionic 3 FileTransfer throws errorcode 1 for download

$
0
0

@udhayakumar wrote:

I’m trying to implement a download function in Ionic 3 using File Transfer plugin file as per the explanation here, https://ionicframework.com/docs/native/file-transfer/. And here’s the code,

import { Component } from ‘@angular/core’;
import { IonicPage, NavController, NavParams, Platform, AlertController } from ‘ionic-angular’;
import { FileTransfer, FileTransferObject } from ‘@ionic-native/file-transfer’;

@IonicPage()
@Component({
selector: ‘page-details’,
templateUrl: ‘details.html’,
providers: [FileTransfer, FileTransferObject],
})
export class DetailsPage {
storageDirectory: string = ‘’;

constructor(public navCtrl: NavController, public navParams: NavParams, public platform: Platform, private transfer: FileTransfer, public alertCtrl: AlertController) {
}

ionViewDidLoad() {
console.log(‘ionViewDidLoad DetailsPage’);
}

downloadImage(imageURL) {
this.platform.ready().then(() => {
imageURL = ‘https://res.cloudinary.com/beinspired/image/upload/fl_attachment/v1514410469/l98gddyf9uoj7k9bljqi.jpg’;
const fileTransfer: FileTransferObject = this.transfer.create();
const imageName = imageURL.split(’/’).pop();

    fileTransfer.download(imageURL, this.storageDirectory + imageName).then((entry) => {
        const alertSuccess = this.alertCtrl.create({
            title: `Download Succeeded!`,
            subTitle: `${imageURL} was successfully downloaded to: ${entry.toURL()}`,
            buttons: ['Ok']
        });
        alertSuccess.present();
    }, (error) => {
        const alertFailure = this.alertCtrl.create({
            title: `Download Failed!`,
            subTitle: `${imageURL} was not successfully downloaded. Error code: ${error.code}`,
            buttons: ['Ok']
        });
        alertFailure.present();
    });
});

}
}
It is throwing error code 1. As per documentation, it is FILE_NOT_FOUND_ERR: 1. But as you can see, there’s a file present in the specified URL.

I tried with different URL, URL with encodeURI() and encodeURIComponent(), but noting works. Any help on this would be greatly helpful and much appreciated.

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 70763

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>