Socket
Socket
Sign inDemoInstall

@ricdotnet/upfile

Package Overview
Dependencies
0
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @ricdotnet/upfile

two simple ways to use: - plain - promise - on event


Version published
Maintainers
1
Install size
19.5 kB
Created

Readme

Source
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
});

FAQs

Last updated on 25 Feb 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc