Filepicker (Will pick different types of docs from wherever location in storage(internal/external))

plugins

#1

I am looking for the Filepicker module/plugin which can able to pick the different types of documents from wherever location in storage(internal/external).
Platforms : IOS & Android

Like https://www.npmjs.com/package/nativescript-file-picker.

Some issues occurred on mentioned plugin. you can see here,

Thats why i am looking for any other way! Advice?

Please suggest!


#2

Since there is no plugin for file picker which will support all type of files like doc, PDFs, xls, txt, zip,…etc,

As a temporary solution I have done workaround on Nativescript-image picker plugin.

By using this awesome plugin, we can get the path of file(whatever file type) then using wonderful Nativescript-Filesystem,

https://docs.nativescript.org/angular/code-samples/file-system

We can process the picked file further.

Thanks @multishiv19 for your suggestion on this on older time.

Hope this may help someone!

Cheers!


#3

I need the same kind of functionality. A file picker control that can pick a document from any where.
Could you please show your work around that you used for the nativescript-imagepicker?


#4

can i get your portion of a code for reference, i mean filepicker+imagepicker. Iam really stuck up with now


#5

@arunwrc & @masood,
For your info,

detail.component.ts

    //image-picker as filepicker
    openFilePicker(prind, catind, prindex, catindex) {   
this.attachService.startSelectionfind(this.observationarray[prind].categorySection[catind].selectedImage, prindex, catindex)
            .then(res => {
                if (res['status'] == "done") {
                    this.observationarray[prind].categorySection[catind].selectedImage.push(
                        { "fileName": res['filename'] }
                    );
                    Toast.makeText("File attached successfully", "Short").show();
                }
            }, err => {
                console.log("Error attaching file!");
            });
    }

attachmenthandler.ts

//attachment service
startSelectionfind(destination, prindex, catindex) {
        let selectedpath;
        let filename;
        let binarySource;
        let sourceFile;
        let filePath;
        let downfolder;
        let downFile;
        let status;
        let flag = true;

        let context = imagepicker.create({
            mode: "single"
        });

        return new Promise<Object>((resolve, reject) => {

            context
                .authorize()
                .then(() => {
                    return context.present();
                })
                .then((selection) => {
                    console.log("Selection done:");
                    selection.forEach((selected)  => {
                        selectedpath = selected.fileUri;
                        filename = selectedpath.substring(selectedpath.lastIndexOf("/") + 1);
                    });

                    let checkfileavail = destination.forEach(item => {
                        if (item.fileName == filename) {
                            flag = false;
                        }
                    });

                    if (flag) {
                        if (filename.substr(0, filename.lastIndexOf('.')).length <= 35) {

                            //read the source file
                            sourceFile = fs.File.fromPath(selectedpath);

                            filePath = path.join(FileSystemConfig.basePath, "Details", "IS", getString("paudSeqno"), prindex, catindex);
                            downFile = Folder.fromPath(filePath).getFile(filename);
                            console.log("attach file path::" + downFile.path);

                            if (downFile) {
                                binarySource = sourceFile.readSync(err => { console.log("Error:" + err); });
                                console.log(binarySource);

                                downFile.writeSync(binarySource, err => {
                                    console.log(err);
                                    reject({ "status": "Error attach file" });
                                });
                                status = 'done';
                            }

                            resolve({ "status": status, "filename": filename });

                        } else {
                            Toast.makeText("File name should be less than 35 characters", "short").show();
                        }

                    }
                    else {
                        Toast.makeText(filename + " file name already exists", "short").show();
                    }
                }).catch((e) => {
                    console.log(e);
                });

        });
    }

Hope it helps!


#6

thanks a lot for response. but got some minor errors. it would be great if you look at pm


#7

@kumaran, Can you share code with these functionality in github? It would be very useful for me


#8

Thanks @kumaran. I will be having a look into it.


#9

im using imagepicker, anyhow it opens gallery but only images it will diplay. it hides all other types of files which i cannot select. i just want its path but imagepicker is not allow me to get other files path. so what to do???


#10

What android version you are testing? Check with latest versions/ API > 21.