How to use async-busboy - 5 common examples

To help you get started, we’ve selected a few async-busboy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github PedroGao / lin-cms-koa-braver / packages / core / src / extend / multipart.ts View on Github external
app.context.multipart = async function(opts?: MulOpts) {
    // multipart/form-data
    if (!this.is('multipart')) {
      throw new Error('Content-Type must be multipart/*');
    }
    let filePromises: Promise[] = [];
    const { fields } = await asyncBusboy(this.req, {
      onFile: async function(fieldname, file, filename, encoding, mimetype) {
        const filePromise = new Promise((resolve, reject) => {
          let bufs = [];
          file
            .on('error', err => {
              file.resume();
              reject(err);
            })
            .on('data', (d: never) => {
              bufs.push(d);
            })
            .on('end', () => {
              const buf = Buffer.concat(bufs);
              resolve({
                size: buf.length,
                encoding: encoding,
github catamphetamine / webapp / code / common / web server.js View on Github external
web.use(mount(mount_path, async function(ctx)
		{
			if (!ctx.is('multipart/form-data'))
			{
				throw new result.errors.Unsupported_input_type(`This is supposed to be a "multipart/form-data" http request`)
			}

			if (requires_authentication !== false && !ctx.user)
			{
				throw new result.errors.Unauthenticated()
			}

			const file_names = []

			const form_data = await busboy(ctx.req,
			{
				limits:
				{
					fileSize: file_size_limit ? file_size_parser(file_size_limit) : undefined
				}
			})

			// const parameters = {}

			// non-channel approach, since `chan` package currently doesn't support async/await
			const { files, fields } = form_data
			const parameters = fields

			// let form_data_item
			// while (form_data_item = yield form_data)
			for (let form_data_item of files)
github rupertqin / koa2-netease-cloudmusic / src / api / info.js View on Github external
router.post('/upload', async (ctx, next)=> {
    const formData = await asyncBusboy(ctx.req)
    const file = formData.files[0]
    const filename = +new Date() + file.filename
    fs.rename(file.path, config.uploadPath + '/img/' + filename)
    Util.resJson(ctx.response, {
        link: '/upload/img/' + filename, 
        // form: retForm
    })
})
github kingdido999 / atogatari / server / src / apis / file.js View on Github external
async function upload (ctx) {
  const { files, fields } = await asyncBusboy(ctx.req)
  const file = files[0]
  const { bangumiTitle, episode, aliases, tags, nsfw } = fields
  const aliasList = JSON.parse(aliases)
  const tagList = JSON.parse(tags)

  if (!bangumiTitle) {
    ctx.throw(400, 'Bangumi title cannot be empty.')
  }

  if (!episode) {
    ctx.throw(400, 'Episode cannot be empty.')
  }

  let bangumi = await Bangumi.findOne({
    title: bangumiTitle
  }).exec()
github kingdido999 / atogatari / server / src / apis / screenshot.js View on Github external
async function upload(ctx) {
  const { files, fields } = await asyncBusboy(ctx.req)

  if (files.length > FILES_COUNT_MAXIMUM) {
    ctx.throw(
      400,
      `You are trying to upload ${files.length} screenshots at a time, 
      which exceeds the limit of ${FILES_COUNT_MAXIMUM}.`
    )
  }

  const fileMap = new Map()

  for (let i = 0; i < files.length; i++) {
    await validateFile(files[i], fileMap, ctx)
  }

  const { tags, nsfw } = fields

async-busboy

Promise based multipart form parser

MIT
Latest version published 3 years ago

Package Health Score

45 / 100
Full package analysis

Popular async-busboy functions