Coder Social home page Coder Social logo

tzvetelin88 / very-big-file-upload-download Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 670 KB

Uploading and Downloading very big files, by handling reading chunks and interruptions. Resumability.

JavaScript 4.79% TypeScript 78.47% HTML 14.14% Less 2.60%

very-big-file-upload-download's Introduction

Solution Design

  • Proper way to download or upload very big files with realtime data streaming and information.
  • Consume less memory and do not break or crash server or client browser.
  • Control Blob chunks to be R/W and streamed.
  • Resumability for uploaded files - continue uploading the file from the last written bytes on the server side.
  • Cancelation for downloading file.
  • Handle Browser refresh and cancel downloading file.

Software set:

  • Socket.io: Bi-directional communication between client and server
  • NodeJS: Backend using native fs to R/W files in proper way by defined chunk size.
  • Angular: Frontend is using File System Access API to instruct client browser to write Blob chunks directly on client OS.

More information:

Application UI Example:

Upload

Download

Interuption due browser refresh or cancel button clicked


Run Backend

Install dependencies

yarn install

Run app:

npx ts-node server/src/server.ts

Exposed on port: 3300 (Change LISTEN_PORT in server.ts)

Run Frontend

cd client/

Install dependencies

yarn install

Run app:

yarn start

Application is listening on

http://localhost:4200/

Configurations - global.conf.ts

// Port to be used in the backend to expose the application.
export const BACKEND_LISTEN_PORT = 3300;

// SocketIO origin URL
export const BACKEND_SOCKETIO_ORIGIN = "http://localhost:4200";

// SocketIO URL that also depends on BACKEND_LISTEN_PORT
export const FRONTEND_SOCKETIO_URL = `http://localhost:${BACKEND_LISTEN_PORT}`;

// This is createReadStream highWaterMark size.
export const RW_CHUNK_SIZE = 8 * 1024 * 100; // 500kb;

// How much of the file we want to read, which defines startingRange for R/W.
export const RW_BUFFER_GET_SIZE = 8 * 1024 * 100; // 500kb

// Stream file here, once all content is ready copy to data Folder.
export const STREAM_FOLDER = "./server/data_stream";

// Directory to save files to
export const DATA_FOLDER = "./server/data";

very-big-file-upload-download's People

Watchers

Tsvetelin Bleskov 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.