2015-12-15 52 views

回答

1

你可以从cordova File插件中获取它。

$cordovaFile.checkFile(uri, '') 
.then(function(entry) { 
    // success 
    var name = entry.name; 

    entry.file(function(data) { 
     // get mime type 
     var mime = data.type; 
     alert(mime); 
    }) 

}, function(error) { 
    // error 
    // show toast 
}); 
+0

你确定这个工程?我通过了如下的URI:'content:// com.android.providers.media.documents/document/video%3A818',它仍然没有任何返回。我每次都得到'FileError'。 – KVISH

0

在角2我用这个:

export class Plugins { 

albums = { 
    open() : Promise<any> { 
     return ImagePicker.getPictures({ 
       quality: 100, 
       maximumImagesCount: 1, 
     }).then((imgUrls) => { 
      return imgUrls; 
     }, (err) => { 
      if(err.error == "cordova_not_available") { 
       alert("Cordova is not available, please make sure you have your app deployed on a simulator or device"); 
      } else { 
       console.log("Failed to open albums: " + err.error); 
      } 
     }); 
    }, 
} 

...

@Component({ 
    templateUrl: 'build/pages/home/home.html', 
    directives: [UploadButton] 
}) 
export class HomePage implements OnInit { 

openAlbums =(): void => { 
var $self = this; 
this._plugins.albums.open().then((imgUrls) => { 
    imgUrls.forEach((imageUrl: string): void => { 
    if (imageUrl) { 
     window.resolveLocalFileSystemURL(imageUrl, function (entry: FileEntry) { 
     entry.file(file=> { 
      console.log('mimeType', file.type); 
     }, ((error:FileError) => console.log(error))); 
     }); 
    } 
    }); 
}); }; 

resolveLocalFileSystemURL还给过成功回调的Entry,我不得不投以FileEntry以访问到文件方法,该文件方法返回File,其延伸具有MIME类型属性的Blob

+0

使用Ionic和Cordova的最新版本时,文件类型没有类型参数。 –

0

我得到它的工作是这样的打字稿及角2:

this._File.resolveLocalFilesystemUrl(somefileUri).then((entry: Entry) => { 
    if (entry) { 
     var fileEntry = entry as FileEntry; 
     fileEntry.file(success => { 
      var mimeType = success.type; 
     }, error => { 
      // no mime type found; 
     });   
    } 
}); 
相关问题