nativescript-imagepicker icon indicating copy to clipboard operation
nativescript-imagepicker copied to clipboard

Android: How to get file extension of images selected using @nativescript/imagepicker

Open SaadmanGTM opened this issue 4 years ago • 1 comments

Hello, I am using @nativescript/imagepicker to select multiple images on android. I would like to only keep the images which have .jpg, .jpeg, and .png extensions.

I am checking the URI using selection[0].android, but the result is: content://com.android.providers.media.documents/document/image%3A52 It contains the image name, but not the file extension.

How can I get the file extension using imagepicker?

This is my implementaiton:

var context = imagePicker.create({
    mode: 'multiple',
    showsNumberOfSelectedAssets: true,
    mediaType: ImagePickerMediaType.Image
})

context
    .authorize()
    .then(function () {

        return context.present()
    })
    .then(function (selection) {

        fileURI = selection[0].android;
        console.log(fileURI);

...

I am using:

@nativescript/core: v8.0.2
@nativescript/imagepicker: v1.0.6

How to get the file extension?

SaadmanGTM avatar Dec 03 '21 14:12 SaadmanGTM

In @nativescript/imagepicker 2.0, it now returns more information about your selection. You can get extension by doing selection[0].filename.split('.').pop() for example.

davecoffin avatar Apr 18 '23 15:04 davecoffin