busboy-file-management
TypeScript icon, indicating that this package has built-in type declarations

3.0.1 • Public • Published

BUSBOY-FILE-MANAGEMENT

Busboy File Management is a library for managing files on the server using Busboy, a Node.js module for analyzing multipart/form-data data.

Installation:

Installation can be done using npm or yarn. run the following command: NPM:

npm install busboy-file-management

YARN:

yarn add busboy-file-management

USE:

import { BusboyFileManagement } from 'busboy-file-management'

or

const { BusboyFileManagement } = require('busboy-file-management');

EXPRESS Middlaware:

Memory Usage

upload_middlaware.js:

import { BusboyFileManagement, MemoryStorage } from 'busboy-file-management'

export default async (req: any, res: any, next: Function) => BusboyFileManagement.config({
        limits:{
            files: 5,
            fileSize: 80 * 1024 * 1024
        },
        storage: new MemoryStorage()
    }).handle(req, res, next);
}

Temporary Usage

import { BusboyFileManagement, TemporaryStorage } from 'busboy-file-management'

export default async (req: any, res: any, next: Function) => BusboyFileManagement.config({
        limits:{
            files: 5,
            fileSize: 80 * 1024 * 1024
        },
        storage: new TemporaryStorage()
    }).handle(req, res, next);
}

Local Usage

import { BusboyFileManagement, LocalStorage } from 'busboy-file-management'

export default async (req: any, res: any, next: Function) => BusboyFileManagement.config({
        limits:{
            files: 5,
            fileSize: 80 * 1024 * 1024
        },
        storage: new LocalStorage('/files')
    }).handle(req, res, next);
}

server.js:

import express from 'express';
import UploadManagement from './upload_middlaware';

const app = express();
const port = 3000;

app.use(express.json());
app.use(UploadManagement)
app.post('/upload', (req: any, res: any) => {
  console.log('Files:', req.files);
  console.log('Fields:', req.body);
  res.send('Upload successful!');
});

app.listen(port, () => {
  console.log(`Server running at http://localhost:${port}`);
});

req.files MemoryStorage data:

Files: [
  {
    fieldname: 'files',
    buffer: <Buffer 54 46 48 30 30 30 30 30 30 30 31 41 52 53 30 32 38 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 32 20 20 20 20 20 20 ... 8350 more bytes>,
    originalname: 'test.txt',
    encoding: '7bit',
    mimetype: 'text/plain',
    truncated: false,
    size: 8400,
    url: ''
  }
]

req.files data Temporary/Local Storage:

Files: [
  {
    fieldname: 'files',
    buffer: <Buffer 54 46 48 30 30 30 30 30 30 30 31 41 52 53 30 32 38 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 32 20 20 20 20 20 20 ... 8350 more bytes>,
    originalname: 'test.txt',
    encoding: '7bit',
    mimetype: 'text/plain',
    truncated: false,
    size: 8400,
    url: 'C:\\Users\XXXXX\AppData\Local\Temp\ad31f46f-f1b5-4f22-a5e7-5df6243bf1fb'
  }
]

Supported storages

Feature Status
MemoryStorage
TemporaryStorage
LocalStorage

Default settings

setting value
files 1
fileSize 25MB

Package Sidebar

Install

npm i busboy-file-management

Weekly Downloads

2

Version

3.0.1

License

ISC

Unpacked Size

33.9 kB

Total Files

12

Last publish

Collaborators

  • jonathan.abas