NativeScript / nativescript-imagepicker

Imagepicker plugin supporting both single and multiple selection.
Apache License 2.0
104 stars 73 forks source link

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

Open SaadmanGTM opened 2 years ago

SaadmanGTM commented 2 years ago

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?

davecoffin commented 1 year ago

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.