使用文件选择器从驱动器中选择文件

时间:2018-01-20 07:17:08

标签: ionic2 ionic3 filechooser

在离子应用中,

使用@ionic-native/filechooser我正在选择驱动器文档。 我会把网址作为

content://com.google.android.apps.docs.storage.legacy/enc%3DOWWfReHHsomYzNVkcRQjdDz2I_xVdBwrW5n6x_6_fOd30Vh7%0A

在此不会获得文件类型。?

如何获取所选文件的类型?

3 个答案:

答案 0 :(得分:0)

selectFile(){
    var filter = { "mime": "application/pdf" }  // text/plain, image/png, image/jpeg, audio/wav etc
    this.fileChooser.open(filter, function(response){
      //success
      console.log("success"+reponse); 
    }, function(error){
      console.log("error"+error)
    })

  }

答案 1 :(得分:-1)

import { File } from '@ionic-native/file';

plugin

获取文件路径后使用上面的插件获取文件详细信息。

我自己没试过,你可以尝试一下。

答案 2 :(得分:-1)

文件选择器

安装此插件

$ ionic cordova plugin add cordova-plugin-filechooser
$ npm install --save @ionic-native/file-chooser

<强> home.ts

export class HomePage {

  img:string;

  constructor(public navCtrl: NavController,
              private fileChooser: FileChooser) {

  }
  openFile(){
    this.fileChooser.open()
    .then((sucess)=>{
      console.log(sucess + 'successfull');
      this.img = sucess;
    })
    .catch((err)=>{
      console.log(err + 'Try again')
    })
  }

}

它将打开您的手机文件管理器,您可以选择任何您想要的文件。

.then((sucess)=>{
      console.log(sucess + 'successfull');
      this.img = sucess;
    })

这部分可帮助您了解所选的文件类型。