🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

react-images-uploading

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-images-uploading

A simple images uploader without UI. Building by yourself

2.1.1
Source
npm
Version published
Weekly downloads
26K
-14.59%
Maintainers
1
Weekly downloads
 
Created
Source

react-images-uploading

NPM JavaScript Style Guide

Images uploader

A simple images uploader without UI. Building by yourself.

#Demo

Introduce blog

Install

npm install --save react-images-uploading

Usage

import * as React from "react";

import ImageUploading from "react-images-uploading";
// { ImageUploadingPropsType, ImageListType, ImageType } is type for typescript

const maxNumber = 10;
const maxMbFileSize = 5;
class Example extends React.Component {
  onChange = (imageList) => {
    // data for submit
    console.log(imageList);
  };

  render() {
    return (
      <ImageUploading
        onChange={this.onChange}
        maxNumber={maxNumber}
        multiple
        maxFileSize={maxMbFileSize}
        acceptType={["jpg", "gif", "png"]}
      >
        {({ imageList, onImageUpload, onImageRemoveAll }) => (
          // write your building UI
          <div>
            <button onClick={onImageUpload}>Upload images</button>
            <button onClick={onImageRemoveAll}>Remove all images</button>

            {imageList.map((image) => (
              <div key={image.key}>
                <img src={image.dataURL} />
                <button onClick={image.onUpdate}>Update</button>
                <button onClick={image.onRemove}>Remove</button>
              </div>
            ))}
          </div>
        )}
      </ImageUploading>
    );
  }
}

Validate

...
  {({ imageList, onImageUpload, onImageRemoveAll, errors }) => (
    <div>
      {errors.maxNumber && <span>Number of selected images exceed maxNumber</span>}
      {errors.acceptType && <span>Your selected file type is not allow</span>}
      {errors.maxFileSize && <span>Selected file size exceed maxFileSize</span>}
    </div>
  )}
...

Props

parametertypeoptionsdefaultdescription
multiplebooleanfalseSet true for multiple choose
maxNumbernumber1000Number of images user can select if mode = "multiple"
onChangefunctionCalled every update
defaultValuearray[{dataURL: ... }, ...]Init data
acceptTypearray['jpg', 'gif', 'png'][]Supported image extension
maxFileSizenumberMax image size(Mb) (will use in the image validation)

Exported options

parametertypedescription
imageListarrayList of images for render. Each item in imageList has some options below.
imageList[index].keystringGenerate filename
imageList[index].dataURLstringUrl image or base64
imageList[index].onUpdatefunctionCall function for replace a new image on current position
imageList[index].onRemovefunctionCall function for remove current image
onImageUploadfunctionCall for upload new image(s)
onImageRemoveAllfunctionCall for remove all image(s)
errorsobjectExport type of validation

License

MIT ©

Keywords

image

FAQs

Package last updated on 23 Apr 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts