node file uploader for large file
npm install node-file-uploader-s3Uploader class is a JavaScript implementation designed to handle file uploads within a Node.js environment. It is equipped to manage uploads from multiple clients simultaneously by leveraging unique file identifiers and organizing files into user- and project-specific directories. Below is a detailed explanation of its components and functionality.
this.uploads object to track the status of ongoing uploads.
uniqueFileId.
userID and projectID directory and creates the directory if necessary. If the file exists, it verifies if the uploaded size matches the expected size.
uniqueFileId, fileSize, userID, projectID, and contentRange.
Content-Range header to determine the current upload chunk's start and end bytes, crucial for handling partial uploads.
uniqueFileId for each file, allowing the server to differentiate between files, even with identical names, and manage simultaneous uploads effectively.
uploads/${userID}/${projectID}/), preventing file conflicts and organizing uploads efficiently.
Content-Range handling, enabling clients to resume interrupted uploads without starting from scratch.
Uploader class provides a robust solution for managing file uploads in web applications, supporting features like resuming uploads, handling files from multiple clients, and organizing files in a structured manner. It leverages Node.js's asynchronous capabilities to efficiently process simultaneous upload requests.
sh
npm install --save node-file-uploader
`
Usage
`sh
const fs = require("fs");
const cors = require("cors");
const express = require("express");
const Uploader = require("node-file-uploader");
const app = express();
`
Initialize the Express app and Uploader instance:
`sh
const uploaderInstance = new Uploader();
`
Define Express routes to handle file upload actions:
`sh
const minioClientSettings = {
endPoint: "your minio end point",
port: port,
useSSL: true|false,
accessKey: "accessKey",
secretKey: "secretKey",
bucket: "bucket",
};
app.get("/upload/status", (req, res) => {
uploaderInstance.uploadStatus(req, res);
});
app.post("/upload/files", (req, res) => {
uploaderInstance.uploadFiles(req, res, minioClientSettings);
});
app.post("/upload/complete", (req, res) => {
uploaderInstance.uploadComplete(req, res, minioClientSettings);
});
``