3.0.1 • Published 7 months ago

busboy-file-management v3.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
7 months ago

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

FeatureStatus
MemoryStorage
TemporaryStorage
LocalStorage

Default settings

settingvalue
files1
fileSize25MB
3.0.1

7 months ago

3.0.0

7 months ago

2.0.4

1 year ago

2.0.3

1 year ago

2.0.2

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago