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

react-file-reader

v1.1.4

Published

A flexible ReactJS component for handling styled HTML file inputs.

Downloads

33,284

Readme

React File Reader

Build Status DAVID

NPM

LIVE DEMO

A flexible ReactJS component for handling styled HTML file inputs.

Install

npm install react-file-reader --save

ChangeLog

  • 1.1.4
    • adds disabled prop for input
  • 1.1.3
    • adds the ability to accept multiple fileTypes as an array
  • 1.1.2
    • fixes an issue where the same file couldn't be selected twice in a row
  • 1.1.1
    • changes the way we're hiding the input, as previously it would break parent elements that were positioned absolutely.
  • 1.1.0
    • adds the ability to return both base64 strings and an HTML5 FileList from handleFiles
  • 1.0.3
    • bumps React version to 15.5 and fixes UNMET peer dependency with webpack
  • 1.0.2
    • fixed an issue w/ prop-types not being available
  • 1.0.1
    • fixed issue w/ uuid4 being a devDependency
  • 1.0.0
    • initial release

Props

Default Props

  • fileTypes: 'image/*'
  • multipleFiles: false
  • base64: false

Required Props

  • a child element/component
    • pass in your customized element to represent your upload input
  • handleFiles
    • a function to handle the selected files from the HTML input

Optional Props

  • elementId
    • set a unique element Id for the input element
    • if this is not set, a random UUID is generated for each input on the page.
  • base64
    • a boolean to convert and return the files as a base64 string
    • multipleFile selection will return an array of base64 strings
  • multipleFiles
    • a boolean enforce single file or multiple file selection
  • fileTypes
  • disabled
    • disable input

Usage

Import React File Reader

import ReactFileReader from 'react-file-reader';

Basic Use

handleFiles = files => {
  console.log(files)
}

<ReactFileReader handleFiles={this.handleFiles}>
  <button className='btn'>Upload</button>
</ReactFileReader>

Response

HTML5 FileList

Base64

When base64 is true, React File Reader returns a JS Object including both the base64 files and the HTML5 FileList. You can access their values at Object.base64 or Object.fileList

handleFiles = (files) => {
  console.log(files.base64)
}

<ReactFileReader fileTypes={[".csv",".zip"]} base64={true} multipleFiles={true} handleFiles={this.handleFiles}>
  <button className='btn'>Upload</button>
</ReactFileReader>

Response

multipleFiles={true}
["data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA", "data:image/png;base64,i..."]
multipleFiles={false}
  "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA..."
Access HTML5 FileList with base64={true}
handleFiles = (files) => {
  console.log(files.fileList)
}

Copyright

Copyright (c)2017 Grillwork Inc. See LICENSE for details.