首页 > 解决方案 > TypeError: Object(...) is not a function at Base64.encodeFile (vendor.js:)

问题描述

@ionic-native/base64/ngx 中的离子问题

TypeError: Object(...) is not a function at Base64.encodeFile (vendor.js:79123) at main.js:183 at t.invoke (polyfills.js:3) at 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)

页面.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)));
  }

}

请有人帮忙

标签: angularcordovaionic-frameworkbase64filepath

解决方案


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


推荐阅读