javascript - 从 Ionic 中的 FILE_URI 获取文件名和扩展名

Mar*_*eng 2 javascript cordova ionic ngcordova

我需要一些关于如何获取由cordova 相机插件挑选/拍摄的文件名称的提示。这是代码,我必须获取图片:

var options = {destinationType: Camera.DestinationType.NATIVE_URI};
options.sourceType = sourceType;
$cordovaCamera.getPicture(options).then(function (newURI) {
  imageFileURI = newURI;
  console.log('NATIVE_URI:\n' + imageFileURI);
  //I need to get the file name and extension here
  window.plugins.Base64.encodeFile(imageFileURI, function (base64Image) {
    base64Data = base64Image;  
  }, function (error) {
    console.log('Error while converting to base64: ' + error);
  });
}, function (error) {
 console.log('Error while picking a photo: ' + error);
});
Run Code Online (Sandbox Code Playgroud)

有没有办法,如何在需要的地方获取文件名和扩展名?谢谢

小智 5

var fileName = imageFileURI.substr(imageFileURI.lastIndexOf('/') + 1);

以上代码获取文件名。

var fileExtension = filename.substr(filename.lastIndexOf('/') + 1);

这将获得文件扩展名。