npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

capacitor-file-selector

v0.0.5

Published

Select File from the Native Filesystem

Downloads

71

Readme

Capacitor File Selector

For detailed tutorial on how to enable dark mode using this plugin visit: https://medium.com/@hinddeep.purohit007/picking-files-in-capacitor-apps-a82c67384496

Demo Application: https://github.com/hinddeep/demo-capacitor-file-picker

Platforms Supported: Android, iOS, and Web/PWA

This plugin can be used to conditionally select files form Android/iOS devices and the web.

Installation

npm install capacitor-file-selector

Android Configuration:

Open MainActivity.java and add the following code inside this.init()

add(FileSelector.class);
Adding the above mentioned line will add the following import statement: 
import com.bkon.capacitor.fileselector.FileSelector;

If you encounter errors, please add both the lines manually to MainActivity.java

To view all the supported Extensions please visit: https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types

iOS Configuration:

To view all the supported extensions please visit: https://developer.apple.com/library/archive/documentation/Miscellaneous/Reference/UTIRef/Articles/System-DeclaredUniformTypeIdentifiers.html

Web Configuration

import { Plugins } from '@capacitor/core'; 
const { FileSelector } = Plugins; 
import ‘capacitor-file-selector’ // Comment out this line when building android/iOS app<br/>

SPECIAL NOTE: When building the app for Android/iOS please do not forget to comment out “import ‘capacitor-file-selector’ ”. The import statement is used to register the web implementation of the plugin. If you register the web implementation of the plugin on native android/iOS app, the code that gets invoked is the web implementation instead of the native Android/iOS implementation.

Select Files:

Supported extensions:- All extensions are supported. Please refer https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types

Supported Broad Categories: “images”, “videos” and “audios”

To allow the selection of all file types use “*”

If you wish to allow the user to select more than file, set the multiple_selection variable to true, else set it to false. Use the ext array to list out all the permitted extensions / broader file categories. The user will be able to select only the files with extensions / category outlined in this ext array.

The ext array IS case sensitive. All characters entered must be in lowercase. If not use Typescript’s map function to convert them into lowercase.

ext = ext.map(v => v.toLowerCase());

Data returned by the file picker contains:

  1. “paths” array - an array of web accessible URL(s)
  2. “original_names” - an array of the name(s) of the file(s)
  3. “extensions” - an array of extension(s) corresponding to the files selected

2 and 3 can be combined to rebuild the original file name. The following function illustrates how to upload files fetched from Android/iOS/Web to any server.

async select() { 
    let multiple_selection = true 
    //let ext = [".jpg",".png",".pdf",".jpeg"] // list of extensions
    let ext = ["MP3", "ImaGes"] // combination of extensions or category 
    //let ext = ["videos", "audios", "images"] // list of all category
    //let ext = ["*"] // Allow any file type
    ext = ext.map(v => v.toLowerCase()); 
    let formData = new FormData(); 
    let selectedFile = await FileSelector.fileSelector({ 
      multiple_selection: multiple_selection, 
      ext: ext 
    }) 

    if(this.platform.is("android")) 
    { 
      let paths = JSON.parse(selectedFile.paths) 
      let original_names = JSON.parse(selectedFile.original_names) 
      let extensions = JSON.parse(selectedFile.extensions) 
      for (let index = 0; index < paths.length; index++) { 
          const file = await fetch(paths[index]).then((r) => r.blob()); 
          formData.append( 
            "myfile[]", 
            file, 
            original_names[index] + extensions[index] 
          ); 
        }
    } 
    else if(this.platform.is("ios")) 
    { 
      for (let index = 0; index < selectedFile.paths.length; index++) { 
        const file = await fetch(selectedFile.paths[index]).then((r) => r.blob()); 
        formData.append( 
          "myfile[]", 
          file, 
          selectedFile.original_names[index] + selectedFile.extensions[index] 
        ); 
      } 
    } 
    else 
    { 
      FileSelector.addListener("onFilesSelected", (data:FileList) => { 
            for(var i = 0; i < data.length; i++) 
            { 
              formData.append( 
                "myfile[]", 
                data.item(i), 
                data.item(i).name + data.item(i).type  
              );
            }
        }); 
    } 
}