All Projects โ†’ doitadrian โ†’ react-butterfiles

doitadrian / react-butterfiles

Licence: MIT license
๐Ÿฆ‹ Component for building file fields - from basic file inputs to drag and drop image galleries.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to react-butterfiles

React Uploady
Modern file uploading - components & hooks for React
Stars: โœญ 372 (+745.45%)
Mutual labels:  files, drag-and-drop, file-upload
Uploadcare Widget
Uploadcare Widget, an ultimate tool for HTML5 file upload supporting multiple file upload, drag&drop, validation by file size/file extension/MIME file type, progress bar for file uploads, image preview.
Stars: โœญ 183 (+315.91%)
Mutual labels:  files, images, file-upload
upload
How to Upload a File to a Server in PHP
Stars: โœญ 83 (+88.64%)
Mutual labels:  files, file-upload
lolisafe
Blazing fast file uploader and awesome bunker written in node! ๐Ÿš€
Stars: โœญ 181 (+311.36%)
Mutual labels:  files, file-upload
Pomf
Simple file uploading and sharing
Stars: โœญ 535 (+1115.91%)
Mutual labels:  files, file-upload
File Drop
A simple file drag and drop custom-element
Stars: โœญ 188 (+327.27%)
Mutual labels:  drag-and-drop, file-upload
react-magic-dropzone
โœจMagically drag and drop files/links for uploading
Stars: โœญ 11 (-75%)
Mutual labels:  files, drag-and-drop
kipp
A flexible file storage server
Stars: โœญ 33 (-25%)
Mutual labels:  files, file-upload
React File Drop
React component for Gmail or Facebook -like drag and drop file uploader
Stars: โœญ 123 (+179.55%)
Mutual labels:  drag-and-drop, file-upload
Express Fileupload
Simple express file upload middleware that wraps around busboy
Stars: โœญ 1,069 (+2329.55%)
Mutual labels:  files, file-upload
Alchemy
๐Ÿ”ฎ File conversion, all from the menu bar
Stars: โœญ 815 (+1752.27%)
Mutual labels:  files, images
Fine Uploader
Multiple file upload plugin with image previews, drag and drop, progress bars. S3 and Azure support, image scaling, form support, chunking, resume, pause, and tons of other features.
Stars: โœญ 8,158 (+18440.91%)
Mutual labels:  files, file-upload
cheryl
PHP web based file manager
Stars: โœญ 44 (+0%)
Mutual labels:  files, file-upload
Ipfs Dropzone
Dropzone.js that uploads to IPFS instead of to an URL
Stars: โœญ 151 (+243.18%)
Mutual labels:  drag-and-drop, file-upload
android-doc-picker
A simple and easy to use documents Picker android library. Choose any documents like pdf, ppt, text, word or media files from your device
Stars: โœญ 37 (-15.91%)
Mutual labels:  files, images
Filepond
๐ŸŒŠ A flexible and fun JavaScript file upload library
Stars: โœญ 11,869 (+26875%)
Mutual labels:  drag-and-drop, file-upload
React Dropzone
Simple HTML5 drag-drop zone with React.js.
Stars: โœญ 8,639 (+19534.09%)
Mutual labels:  drag-and-drop, file-upload
Angular File Uploader
Angular file uploader is an Angular 2/4/5/6/7/8/9/10 + file uploader module with Real-Time Progress Bar, Responsive design, Angular Universal Compatibility, localization and multiple themes which includes Drag and Drop and much more.
Stars: โœญ 92 (+109.09%)
Mutual labels:  drag-and-drop, file-upload
Chibisafe
Blazing fast file uploader and awesome bunker written in node! ๐Ÿš€
Stars: โœญ 657 (+1393.18%)
Mutual labels:  files, file-upload
Contentmanager
Android library for getting photo or video from a device gallery, cloud or camera. Working with samsung devices. Made by Stfalcon
Stars: โœญ 108 (+145.45%)
Mutual labels:  files, images

๐Ÿฆ‹ react-butterfiles

Build Status Coverage Status code style: prettier All Contributors PRs Welcome

A small component for building file upload fields of any type, for example a simple file upload button or an image gallery field with drag and drop support and preview of selected images.

Install

npm install --save react-butterfiles

Or if you prefer yarn:

yarn add react-butterfiles

Quick Example:

Create a simple file field which consists of a drop zone and a file upload button (for cases where drag and drop is not convenient). Multiple PDF / JPG files are accepted, but with the following restrictions:

  • 3 files max
  • max 2MB in size per file
  • max 10MB in size for the whole selection
import Files from "react-butterfiles";
<Files
    multiple={true} 
    maxSize="2mb"
    multipleMaxSize="10mb"
    multipleMaxCount={3}
    accept={["application/pdf","image/jpg","image/jpeg"]}
    onSuccess={files => this.setState({ files })}
    onError={errors => this.setState({ errors })}
>
    {({ browseFiles, getDropZoneProps, getLabelProps }) => (
        <>
            <label {...getLabelProps()}>Your files</label>
            <div {...getDropZoneProps({ className: "myDropZone" })}/>
            <button onClick={browseFiles}>Select files...</button>
            <ol>
                {this.state.files.map(file => (
                    <li key={file.name}>{file.name}</li>
                ))}
                {this.state.errors.map(error => (
                    <li key={error.file.name}>
                        {error.file.name} - {error.type}
                    </li>
                ))}
            </ol>
        </>
    )}
</Files>

More examples on https://react-butterfiles.netlify.com.

Props

Prop Type Default Description
accept Array<string> [] Defines which file types will be accepted. Example: ["application/pdf"].
multiple boolean false Allow multiple file selection by setting this prop to `true.
maxSize string "2mb" Defines maximum file size (bytes lib used behind the scenes). Example: "10mb"
multipleMaxSize string "10mb" Useful only if multiple prop is set to true. Defines max. file size of all selected files.
multipleMaxCount number null Useful only if multiple prop is set to true. Defines max. allowed selected files.
convertToBase64 boolean false If true, selected files will also be converted to baser64 format (useful when working with images / thumbnails).
onSuccess (files: Array<SelectedFile>) => void undefined Callback that will get executed once a valid file selection has been made (via browse files dialog or drag and drop). Each file will have a random id assigned to it.
onError (errors: Array<FileError>) => void undefined Callback that will get executed once an invalid file selection has been made. Each error will have a random id assigned to it. More info about possible errors below.

Render (children) prop

Render prop gives you access to three callbacks:

Prop Type Description
browseFiles BrowseFilesParams => void Once executed, file browser will be shown. Useful for file upload buttons. The callback can also accept custom onSuccess and onError callbacks, that will override the main ones.
validate (files: Array<File>) => Array<FileError> Enables manual validation of files. Eg. after editing the selected image in an image editor.
getDropZoneProps (additionalProps: ?Object) => Object Props that need to be spread to a drop zone. Additional props can be passed, for example className or style.
getLabelProps (additionalProps: ?Object) => Object Props that need to be spread to your file field's label. Additional props can be passed, for example className or style.

Note that you don't need to have both upload file and drop zone, you can use only one if that's your requirement. For example, to create a simple file field, you would only need to use the browseFiles callback.

Selection error types

While selecting and dropping files, if there are one or more that do not comply with the rules that were set via props, an onError callback will be triggered, with all of the errors passed as the first argument.

Every error in the array will have one of the following error types.

Type Description
unsupportedFileType This can only happen via drag and drop since file browser dialog won't let users choose files of invalid type.
maxSizeExceeded One or more file sizes are greater than maxSize value.
multipleMaxCountExceeded User selected more files than allowed (more than multipleMaxCount).
multipleMaxSizeExceeded User selected one or more files with their total size greater than allowed (more than multipleMaxSize).
multipleNotAllowed This can only happen via drag and drop since file browser dialog won't let users select two or more files if multiple was not set to true.

Contributors

Thanks goes to these wonderful people (emoji key):

Adrian Smijulj
Adrian Smijulj

๐Ÿ’ป ๐Ÿ“– ๐Ÿ’ก ๐Ÿ‘€ โš ๏ธ
readeral
readeral

๐Ÿ’ป ๐Ÿ“–

This project follows the all-contributors specification. Contributions of any kind welcome!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].