# component-file-picker

> File picker component

Latest version **0.2.1** (published 2014-07-14) · 0 weekly downloads

## Install

```sh
npm install component-file-picker
pnpm add component-file-picker
yarn add component-file-picker
bun add component-file-picker
```

## Health

**Score 10/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; low quality score; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.1 |
| Published | 2014-07-14 |
| First published | 2014-07-14 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 23 |
| Author | Damian Suarez |
| Maintainers | tootallnate |
| Keywords | browser, file, file-picker, picker, component |

## Links

- npm: https://www.npmjs.com/package/component-file-picker
- Repository: https://github.com/component/file-picker
- Issues: https://github.com/component/file-picker/issues
- npm.io page: https://npm.io/package/component-file-picker

## Dependencies (1)

- [component-event](https://npm.io/package/component-event.md) 0.1.4

## Alternatives

- [unionfs](https://npm.io/package/unionfs.md) — 2.2M weekly downloads
- [path-starts-with](https://npm.io/package/path-starts-with.md) — 35.9K weekly downloads
- [redzip](https://npm.io/package/redzip.md) — 1.2K weekly downloads
- [vscode-anymatch](https://npm.io/package/vscode-anymatch.md) — 848 weekly downloads
- [@ledgerhq/coin-filecoin](https://npm.io/package/@ledgerhq/coin-filecoin.md) — 793 weekly downloads

## Recent versions

- 0.2.1 (latest) — 2014-07-14

## README

# 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

```js
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](http://stackoverflow.com/questions/181214/file-input-accept-attribute-is-it-useful/10503561#10503561).

  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

---
_Source: https://npm.io/package/component-file-picker · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
