【问题标题】:Choosing file from drive using file chooser使用文件选择器从驱动器中选择文件
【发布时间】:2018-01-20 07:17:07
【问题描述】:

在离子应用中,

使用@ionic-native/filechooser 我正在选择驱动器文档。 我将获取网址为

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

在这不会得到File的类型。?

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

【问题讨论】:

    标签: ionic2 ionic3 filechooser


    【解决方案1】:

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

    plugin

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

    我自己没试过,你可以试试。

    【讨论】:

      【解决方案2】:

      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)
          })
      
        }

      【讨论】:

        【解决方案3】:

        文件选择器

        安装此插件

        $ 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;
            })
        

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2021-04-22
          • 1970-01-01
          • 2018-04-07
          • 2022-12-15
          • 2019-05-01
          • 1970-01-01
          • 2013-08-13
          • 2020-03-26
          相关资源
          最近更新 更多