A react hook for uploading large files that need chunking.

Overview

NPM TypeScript Licence React Yarn

React Chunked Uploader

A react hook for uploading large files that need chunking (for example for uploading to Cloudinary). It uses axios and provides loading state and progress value.

Installation

yarn add react-chunked-uploader

or

npm i react-chunked-uploader

Usage

Import the hook from the package:

import useChunkedUploader from 'react-chunked-uploader';

Into your React component:

const { uploadFile, cancelUpload, isLoading, progress } = useChunkedUploader();

const uploadImage = async (file: File, data: FormData) => {
  try {
    const result = await uploadFile({ file, url: 'YOUR_UPLOAD_URL', data });
    return result;
  } catch (error) {
    console.error(error);
  }
};

API

uploadFile

A function to upload a file with specific form data.

uploadFile({ file, url, data, chunkSize });

Options:

Name Type Required Default value
file File yes -
url string yes -
data FormData no -
chunkSize number (Bytes) no 6 * 1024 * 1024

Return type:

Promise<AxiosResponse[]>;

isLoading

A boolean that indicates the loading status of the uploading data.

Name Type Default value
isLoading boolean false

progress

A number that indicates the progress value of the uploading process.

Name Type Default value
progress number 0

cancelUpload

A function to cancel upload operation.

Name Type
cancelUpload () => void

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Add your changes: git add .
  4. Commit your changes: git commit -am 'Add some feature'
  5. Push to the branch: git push origin my-new-feature
  6. Submit a pull request 😎

Versioning

We use SemVer for versioning.

Authors

License

MIT License © Raffi Dilanchian

You might also like...
A React hook to fetch ENS records from a domain.

use-ens A React hook to fetch ENS records from a domain. Install pnpm i use-ens Example import React, { useEffect } from 'react' import { useWeb3React

The complete type-safe MUI and react-hook-form combo and beyond with simple API

The complete type-safe MUI and react-hook-form combo and beyond with simple API

📈 Easily interpolate to a provided value with a simple React hook.

∿ use-smooth-count ∿ Easily interpolate to a provided value with a simple React hook. npm install use-smooth-count or yarn add use-smooth-count Demo E

 Electron React Boilerplate uses Electron, React, React Router, Webpack and React Fast Refresh.
Electron React Boilerplate uses Electron, React, React Router, Webpack and React Fast Refresh.

Electron React Boilerplate uses Electron, React, React Router, Webpack and React Fast Refresh.

A monorepo boilerplate for react web and react native. Uses react-native-web to reduce time invested in making the same components for mobile and web

Monorepo template Get Started Run the following command to install all the dependencies in the right location yarn lerna bootstrap yarn workspace @mar

React-Typescript-Webpack was config with React, Typescript, and Webpack without CRA. Faster to start your next react project.
React-Typescript-Webpack was config with React, Typescript, and Webpack without CRA. Faster to start your next react project.

Start your react typescript project with manual webpack config in seconds Flexible to control webpack, easy to deploy Keywords: React Starter, Webpack

Black Dashboard React is a beautiful Bootstrap 4, Reacstrap and React (create-react-app) Admin Dashboard with a huge number of components built to fit together and look amazing.
Black Dashboard React is a beautiful Bootstrap 4, Reacstrap and React (create-react-app) Admin Dashboard with a huge number of components built to fit together and look amazing.

Black Dashboard React Black Dashboard React is a beautiful Bootstrap 4, Reacstrap and React (create-react-app) Admin Dashboard with a huge number of c

Now UI Kit React - Free Bootstrap 4, React, React Hooks and Reactstrap UI Kit
Now UI Kit React - Free Bootstrap 4, React, React Hooks and Reactstrap UI Kit

Now UI Kit React is a free Bootstrap 4, React, React Hooks and Reactstrap UI Kit provided for free by Invision and Creative Tim. It is a beautiful cross-platform UI kit featuring over 50 elements and 3 templates.

Build React Typescript Authentication and Authorization example using React Hooks, React Router, Axios and Bootstrap
Build React Typescript Authentication and Authorization example using React Hooks, React Router, Axios and Bootstrap

React Typescript JWT authentication and authorization example with Hooks, React router, Axios - Role based authentication example

Releases(v0.2.0)
Owner
Raffi Dilanchian
👨🏻‍💻 Frontend Engineer 🎓 M.Sc. in Computer System Architecture (University of Isfahan) 🛸 Home automation and embedded systems enthusiast
Raffi Dilanchian
A toolkit for React, Preact, Inferno & vanilla JS apps, React libraries and other npm modules for the web, with no configuration (until you need it)

nwb nwb is a toolkit for: Quick Development with React, Inferno, Preact or vanilla JavaScript Developing: React Apps Preact Apps Inferno Apps Vanilla

Jonny Buchanan 5.5k Jan 3, 2023
This project is designed to help those who use antd to develop a website(or web app). Maybe also need to use redux, router and so on.

react-antd-redux-router-starter This project is designed to help those who use antd to develop a website(or web app). Maybe also need to use redux, ro

yuzhou 102 Nov 21, 2022
Brownie-next-mix - Everything you need to use NextJS with Brownie

Brownie NextJS Mix This mix comes with everything you need to start using NextJS

Rafael Abuawad 9 Jun 20, 2022
A simple, delicate and modern template for who anyone need portfolio

A simple, delicate and modern template for who anyone need portfolio

Abdullah Öztürk 6 Sep 19, 2022
Generates large React projects for use in benchmarking

React Benchmark Generator This script helps generate large files with custom React components for the purposes of benchmarking React/JavaScript toolin

multiprocess.io 5 Dec 11, 2022
Large SPA boilerplate use react redux webpack babel es6 express browsync nodemon...

React-workflow Why Large SPA application is hard to design, because a lot of things need to consider The boilerplate had solved the difficulty for

云霜儿 66 Mar 27, 2021
Large SPA boilerplate use react redux webpack babel es6 express browsync nodemon...

React-workflow Why Large SPA application is hard to design, because a lot of things need to consider The boilerplate had solved the difficulty for

云霜儿 66 Mar 27, 2021
This project is collection of large projects's source code (codebases), built with Reactjs. Eg: Bestbuy, Postman, Trello, Udacity, Coursera, Skillshare, Invision, Intercom, Pipedrive, ... and more.

This project is collection of large projects's source code (codebases), built with Reactjs. Eg: Bestbuy, Postman, Trello, Udacity, Coursera, Skillshare, Invision, Intercom, Pipedrive, ... and more.

null 1.1k Dec 30, 2022
A Cool VSCode extension that lets you create react component files/folders instantly with boilerplate code. It also handles imports/exports on its own.

React Component Generator v1.0.0 A cool VSCode extension that lets you create your component's files/folders instantly with boilerplate code. Also aut

Udit Kumar 8 Dec 7, 2022
A CLI and toolbox to extract information from React component files for documentation generation purposes.

react-docgen react-docgen is a CLI and toolbox to help extracting information from React components, and generate documentation from it. It uses ast-t

React Community 3.3k Dec 27, 2022