GithubHelp home page GithubHelp logo

file-select.js's Introduction

file-select

prompt user for selecting files. +promises, -forms

prompt

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

npm i --save file-select

Usage

Using a standalone release build

HINT: Check out newest releases here!

<script type="text/javascript" src="/path/to/file-select.min.js"></script>
<script type="text/javascript">

  window.onload = function () {
    fileSelect().then(console.log.bind(console))
  }

</script>

JS ES-stage-0 a.k.a. ES-awesome

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

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

file-select.js's People

Stargazers

<jaxcoder /> avatar Happy Developer avatar Alan S. Ferreira avatar Luiz Gonçalves ☕ avatar Jingsong Gao avatar José Moreira avatar Mathieu M-Gosselin avatar lazzzis avatar 文蔺 avatar Nikita avatar Mike Rodrigues De Lima avatar

Watchers

James Cloos avatar José Moreira avatar <jaxcoder /> avatar  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.