Git Product home page Git Product logo

file-picker-1's Introduction

File Picker

Opens a file picker dialog upon being called. Doesn't need a DOM element or pre-existing <input type="file">.

Note: This component inserts the element when required, so the body element needs to be loaded beforehand.

Note: For security reasons, file-picker must be triggered by an original DOM event (click, touchstart, keyup, etc.). It cannot be called onload or in a timeout.

Installation

$ component install component/file-picker

Usage

var filePicker = require('file-picker');

// Upload a single file
$('single-link').click(function() {
  filePicker(function(files){});
});

// Upload multiple files (on supported web browsers)
$('multiple-link').click(function() {
  filePicker({ multiple: true }, function(files){});
});

// Upload a directory (on supported web browsers)
$('directory-link').click(function() {
  filePicker({ directory: true }, function(files){});
});

// Accept only image files or .psd files
$('image-link').click(function() {
  filePicker({ accept: [ 'image/*', '.psd' ] }, function(files){});
});

API

filePicker(opts, fn)

Valid options:

  • multiple (Boolean) whether the user can select multiple files if the UA supports it (defaults to false).
  • directory (Boolean) whether the user can select a directory if the UA supports it (defaults to false).
  • accept (String) tell the browser to only allow selecting files of this type. If several types, you may pass in an array of types. Some examples.

The callback fn will only be invoked if the underlying <input> fires a change event. It will receive the following parameters:

  • The files array from the <input> (not available on IE9).
  • The change event object.
  • The underlying <input> element reference (detached from DOM).

Browser support

  • Internet Explorer 9+
  • Firefox
  • Chrome
  • Opera
  • Safari
  • Mobile Safari
  • Android Browser

License

MIT

file-picker-1's People

Contributors

chemzqm avatar coreh avatar forbeslindesay avatar lancejpollard avatar matthewmueller avatar rauchg avatar retrofox avatar tootallnate avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.