1.0.0 • Published 2 months ago

@ricdotnet/upfile v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

How to use (only with expressjs)

two simple ways to use:

  • plain
  • promise
  • on event
import { Request, Response, NextFunction } from 'express';
import { Upfile } from '@ricdotnet/upfile';

// plain
// this version will use call the next() function when we finish parsing the incoming body
function upload(req: Request, res: Response, next: NextFunction) {
  const upfile = new Upfile('uploads path');

  upfile.parseIncomingBody(req, res, next);
}

// event
// we have an 'uploaded' event that gets fired when we finish parsing the incoming body
function upload(req: Request, res: Response, next: NextFunction) {
  const upfile = new Upfile('uploads path');

  upfile.parseIncomingBody(req, res);

  upfile.on('uploaded', () => next());
}

// promise
// this just allows us to await until we finish parsing the incoming body
async function upload(req: Request, res: Response, next: NextFunction) {
  const upfile = new Upfile('uploads path');

  await upfile.parseIncomingBody(req, res);

  next();
}

route.post('/upload', upload, (req: Request, res: Response) => {
  // data available on
  console.log(req.files); // files
  console.log(req.body); // other data
});
1.0.0

2 months ago

0.0.15

2 months ago

0.0.12

2 years ago

0.0.13

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5-beta.0

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.0

2 years ago