Code Monkey home page Code Monkey logo

file-uploader's Introduction

file-uploader

Full stack file uploader project. intro

Client Side

1

  • 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
2 3
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

Props

  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;
  }

Server Side

  • 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);

Installation

  • 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

file-uploader's People

Contributors

bk52 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.