TypeError:Object(...)不是Base64.encodeFile(vendor.js :)的函数

时间:2019-04-11 18:01:20

标签: angular cordova ionic-framework base64 filepath

@ ionic-native / base64 / ngx中的

ionic问题

  

TypeError:Object(...)不是函数      在Base64.encodeFile(vendor.js:79123)      在main.js:183      在t.invoke时(polyfills.js:3)      在Object.onInvoke(vendor.js:5134)      在t.invoke时(polyfills.js:3)      在r.run(polyfills.js:3)      在polyfills.js:3      在t.invokeTask(polyfills.js:3)      在Object.onInvokeTask(vendor.js:5125)      在t.invokeTask(polyfills.js:3)

page.ts

import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams, AlertController, ToastController, ActionSheetController, LoadingController } from 'ionic-angular';
import { RestProvider } from '../../../providers/rest/rest';
import { DatePipe } from '@angular/common';
import { FilePath } from '@ionic-native/file-path';
import { FileChooser } from '@ionic-native/file-chooser';
//import { Base64 } from '@ionic-native/base64';
import { Base64 } from '@ionic-native/base64/ngx';
//import { Camera } from '@ionic-native/camera';
import { Camera } from '@ionic-native/camera/ngx';


/**
 * Generated class for the AlerteFinDroitDecesPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-alerte-fin-droit-deces',
  templateUrl: 'alerte-fin-droit-deces.html',
})
export class AlerteFinDroitDecesPage {

  constructor(public navCtrl: NavController,
    public navParams: NavParams,
    public Rest: RestProvider,
    public alertConroller: AlertController,
    public datepipe: DatePipe,
    public toastCtrl: ToastController,
    private fileChooser: FileChooser,
    public actionSheetCtrl: ActionSheetController,

    private filePath: FilePath,
    public base64: Base64,
    public camera:Camera,
    public loadingCtrl: LoadingController) {
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad AlertmariagePage');
  }

  getImage(){
    // choose your file from the device
    console.log("getImage");

    this.fileChooser.open().then(uri => {
    console.log("uri",uri);
        //alert('uri'+JSON.stringify(uri));
        // get file path
        this.filePath.resolveNativePath(uri)
        .then(file => {
      //alert('file'+JSON.stringify(file));
      console.log("file",file);
            let filePath: string = file;
            if (filePath) {
        this.base64.encodeFile(filePath).then((base64File: string) => {

            console.log("filePath",filePath);
            console.log("base64File",base64File);

            //alert('base64File'+JSON.stringify(base64File));

                }, (err) => {
          //alert('err'+JSON.stringify(err));
          console.log("err",err);
                });
            }
        })
        .catch(err => console.log(err));
    })
    .catch(e => alert('uri'+JSON.stringify(e)));
  }

}

请某人帮助

1 个答案:

答案 0 :(得分:0)

根据插件版本更新您的 base64 节点模块版本。我通过从节点模块中删除它并运行 npm install @ionic-native/base64@4.12.2

解决了它