Full stack file uploader project.
- Click or drag and drop for select file.
- Show upload progress
- Set maximum file size
- Set allowed file types
- Single or multiple file upload
- Developed with Typescript
- Unit test with react-testing-library
- Show files as a list or chip style
List Style | Chip Style |
---|---|
import React, { useState } from 'react';
import UploadController from './components/UploadController';
import { UploadStatus } from './global/types';
const App = () => {
const [files,setFiles]=useState<File[]>([]);
const [status, setStatus]=useState<UploadStatus>("Waiting");
const StartUpload=async ()=>{
// Send Files
}
const CancelUpload=()=>{
// Cancel Upload
}
return <UploadController
onStartUpload={StartUpload}
onCancelUpload={CancelUpload}
onFileChange={(file)=>setFiles(file)}
status={status} />
}
export default App
export interface IUploadController{
/** Name of input field. */
name?:string;
/** Upload status of files. Default value is "Waiting" */
status?:UploadStatus;
/** Multiple or single file upload. Default value is true. */
allowMultiple?:boolean;
/** Maximum total file size in byte. Default value is 1048576. */
allowedTotalByteSize?:number;
/** Accepted file types. Default value is ".jgp, .jpeg, .gif, .png" */
acceptedFileTypes?: string;
/** File list type. Default value is "List" */
fileListType?: "Chip"|"List";
/** Upload text under the icon. */
uploadText?:string;
/** Allow file extensions text */
fileExtentionText?: string;
/** Upload file percentage */
uploadPercentage?:number;
/** Trigger when file selected or removed. Return file list. */
onFileChange?:(files:File[])=>void;
/** Trigger when clicked start upload button */
onStartUpload?:()=>void;
/** Trigger when clicked stop upload button */
onCancelUpload?:()=>void;
}
- Set maximum file size
- Developed with Typescript
- Upload files to local folder or S3 Bucket or both.
const UPLOAD_PATH= `${__dirname}/uploads/`;
const options:IUploadOptions={
uploadLocal:true,
uploadPath:UPLOAD_PATH,
uploadS3Bucket:true,
randomFileName:false,
totalUploadByte:1024*1024,
}
const result=await UploadFiles(req.files, options);
- Clone repository git clone https://github.com/bk52/file-uploader.git
- Install server side
- Enter server folder cd server
- Change .env.development to .env and fill credentials
- Install packages npm install
- Run server npm run dev
- Install client side
- Enter client folder cd client
- Install packages yarn install
- Run server yarn start