2015-12-15 56 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; 
     });   
    } 
}); 
相關問題