https://github.com/cusspvz/file-select.js
:file_folder: prompt user for selecting files. +promises, -forms
https://github.com/cusspvz/file-select.js
Last synced: about 2 months ago
JSON representation
:file_folder: prompt user for selecting files. +promises, -forms
- Host: GitHub
- URL: https://github.com/cusspvz/file-select.js
- Owner: cusspvz
- License: other
- Created: 2016-11-08T11:24:26.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-12-02T10:58:26.000Z (over 8 years ago)
- Last Synced: 2025-02-24T05:17:59.813Z (about 2 months ago)
- Language: JavaScript
- Homepage:
- Size: 15.6 KB
- Stars: 11
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# file-select
prompt user for selecting files. +promises, -forms

## What is this?
This allows the developer to ask their app/website users for files without
creating a form and a file input element.## Installation
```bash
npm i --save file-select
```## Usage
### Using a standalone release build
**HINT:** Check out newest releases [here](https://github.com/cusspvz/file-select.js/releases)!
```html
window.onload = function () {
fileSelect().then(console.log.bind(console))
}```
### JS ES-stage-0 a.k.a. ES-awesome
```js
import req from 'superagent'
import fileSelect from 'file-select'async function uploadImages () {
try {
const image = await fileSelect({
maxFileSize: 1024 * 1024 * 10,
multiple: false,
accept: 'image/*'
})const res = await req.post('/').attach('image',image)
alert( 'uploaded' )} catch ( err ) {
alert( 'cancelled' )
}
}
```### JS ES5 / CommonJS
```js
var req = require( 'superagent' )
var fileSelect = require( 'file-select' )function uploadImages () {
return Promise.try(function () {
return fileSelect({
maxFileSize: 1024 * 1024 * 10,
multiple: false,
accept: 'image/*'
})
})
.then(function ( images ) {
return req.post('/').attach('image',image)
})
.then(function ( res ) {
alert( 'uploaded' )
})
.catch(function ( err ) {
alert( 'cancelled' )
})
}
```## API
### `fileSelect`
#### `options`
`Object`
Object with options.#### `options.multiple`
`boolean`
Allows multiple files selection.#### `options.maxFileSize`
`Number`
Limits select size PER FILE.#### `options.accept`
`String | false`
String with mime types and file extensions separated by commas.Examples:
- `.jpg,.jpeg`
- `image/jpeg,.jpeg,.jpg`
- `image/jpeg`
- `.pdf`
- `.mp3`## LICENSE - POL-v1
[Private-Open License v1](https://raw.githubusercontent.com/cusspvz/pol/master/POL-1.0.md)