nativescript-community / ui-document-picker

A NativeScript plugin that allows you to select files from the device.
https://nativescript-community.github.io/ui-document-picker/
Apache License 2.0
10 stars 8 forks source link

Error in v-on handler: "TypeError: Cannot read property 'then' of undefined" when openFilePicker #16

Closed xpalacincreditoh closed 2 years ago

xpalacincreditoh commented 2 years ago

When call openFilePicker console return: Error in v-on handler: "TypeError: Cannot read property 'then' of undefined"

My SelectModal.vue:

openPicker(item) {
                switch (item.key) {
                    case 'photo':
                        this.mediaService.showCameraPicker().then((files) => {
                            item.files = files;
                            this.$modal.close(item);
                        });
                        break;
                    case 'gallery':
                        this.mediaService.showGalleryPicker().then((files) => {
                            item.files = files;
                            this.$modal.close(item);
                        });
                        break;
                    case 'file':
                        this.mediaService.showFilePicker().then((files) => {
                            item.files = files;
                            this.$modal.close(item);
                        });
                        break;
                    default:
                        this.$modal.close(item);
                        break;
                }
            },

My MediaService.js:

import { openFilePicker } from '@nativescript-community/ui-document-picker';

export default class MediaService {
    showCameraPicker() {
        openFilePicker({
            extensions: ['jpg'],
            multipleSelection: true,
        });
    }
    showGalleryPicker() {
        openFilePicker({
            extensions: ['jpg'],
            multipleSelection: true,
        });
    }
    showFilePicker() {
        openFilePicker({
            extensions: ['pdf'],
            multipleSelection: true,
        });
    }
}
farfromrefug commented 2 years ago

@xpalacincreditoh your code is false you dont return a promise. Please this is a place to report bugs on the plugin