1.0.0 • Published 1 year ago

@ricdotnet/upfile v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year 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

1 year ago

0.0.15

1 year ago

0.0.12

3 years ago

0.0.13

3 years ago

0.0.10

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5-beta.0

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.0

3 years ago