Cordova 3.4.0: Camera.getPicture () returns an encoded URI if selected from GALLERY

I use the Camera.getPicture () API to capture an image or select an image from the GALLERY. When I take a picture with the camera, it returns me a FileEntry with the correct URL with the file name and extension. But when I select a file from the gallery, it returns "FileEntry.fullPath" as /com.android.providers.media.documents/document/image%3A322 and sometimes / media / external / images / media / 319

What I want, I want to check the supported file type (i.e. jpg / jpeg) and the actual file name.

Is there a way to get the file name with the extension that is selected.

Thanks in advance.

Code snippet:

        var data = {};
        if( type === CAMERA){
            data = {
                        quality: quality,
                        destinationType: FILE_URI,
                        encodingType: JPEG, targetWidth: 1200, targetHeight: 1200,
                        saveToPhotoAlbum: true
                    };
        }
        else
        {
            data = {
                        destinationType: FILE_URI,
                        sourceType: PHOTOLIBRARY,
                        mediaType: ALLMEDIA

                    };
        }


        navigator.camera.getPicture(
                successCallback, errorCallback, data
        );   

      //The success callback method is : 
       successCallback: function(imageURI, param)
       {
                 //HERE THE imageURI value is coming with different format if selected from GALLERY
                 window.resolveLocalFileSystemURI(imageURI, 
            function(fileEntry) {fileEntry.file(onSuccess,onError);},
                            function(evt) {onError.call(this,evt.target.error);} );

       }
+4
source share
2

URI "content://" URI "file://" : https://www.npmjs.com/package/cordova-plugin-filepath.

URI "file://" Cordova resolveLocalFileSystemURL().

, .

if (fileUri.startsWith("content://")) {
    //We have a native file path (usually returned when a user gets a file from their Android gallery)
    //Let convert to a fileUri that we can consume properly
    window.FilePath.resolveNativePath(fileUri, function(localFileUri) {
        window.resolveLocalFileSystemURL("file://" + localFileUri, function(fileEntry) {/*Do Something*/});
    });
}
+6

getpicture   navigator.camera.getPicture(cameraSuccess, cameraError, [cameraOptions]);

cameraOptions

{ quality : 75,
  destinationType : Camera.DestinationType.DATA_URL,
  sourceType : Camera.PictureSourceType.CAMERA,
  allowEdit : true,
  encodingType: Camera.EncodingType.JPEG,
  targetWidth: 100,
  targetHeight: 100,
  popoverOptions: CameraPopoverOptions,
  saveToPhotoAlbum: false };

.

Android Quirks

Android 4.4: Android 4.4 , . . - getPicture() , "", "", "" " ", FILE_URI. , , "". fooobar.com/questions/12209/.... . CB-5398 .

Android , Cordova . .

fileEntry, file() mettadatas

 function cameraSuccess(urls) {

       window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(){

                    // alert('success requestFileSystem');

                 }, function(){
                 //error

                   });

        window.resolveLocalFileSystemURI(urls, function(fileEntry){


                   fileEntry.file(function(file){

                             // alert(JSON.stringify(file)); //view full metadata
                                var type = file.type;
                                var nameoffile = file.name;

                               }, function(){

                                //error                                                 
                                });

                  },function(){

                 // error 
                  } ); 

-

+3

Source: https://habr.com/ru/post/1534665/


All Articles