Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
SaadmanGTM opened this issue Dec 3, 2021 · 1 comment

Comments

@SaadmanGTM
Copy link

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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants