文件选择器插件用于文件选择。。它不会为您提供文件信息,如大小mimetype等。您需要一些其他插件,如
file
和
filepath
从文件中获取此信息。我在下面提到了这些链接,并添加了我的示例代码,请查看如何通过这些插件获取这些信息。
构造器
import { FileChooser } from '@ionic-native/file-chooser/ngx';
import { FilePath } from '@ionic-native/file-path/ngx';
import { File } from '@ionic-native/file/ngx';
constructor(
private fileChooser: FileChooser,
private filepath : FilePath,
private file : File,
private plt : Platform
) { }
文件选择功能
async selectFile(){
if(this.plt.is('android')){
const selectedFile : string = await this.fileChooser.open();
const resolvedPath = await this.filepath.resolveNativePath(selectedFile);
const fileEntry = await this.file.resolveLocalFilesystemUrl(resolvedPath) as any;
fileEntry.file((fileInfo)=>{
console.log('File Info ', fileInfo);
//sample response file mime type size etc you can use it as per your requirement
// end: 3028
// lastModified: 1610953273000
// lastModifiedDate: 1610953273000
// localURL: "cdvfile://localhost/sdcard/Download/sample.pdf"
// name: "sample.pdf"
// size: 3028
// start: 0
// type: "application/pdf"
})
}else{
//For ios device
const selectedFile : string = await this.filePicker.pickFile() ;
const fileEntry = await this.file.resolveLocalFilesystemUrl('file:///'+selectedFile) as any;
fileEntry.file((fileInfo)=>{
console.log('File Info ', fileInfo);
})
}
}
https://ionicframework.com/docs/native/file
https://ionicframework.com/docs/native/file-path