How to use co-busboy - 4 common examples

To help you get started, we’ve selected a few co-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 marmelab / ZeroDollarHomePage / src / api / claims / claimsApiRoutes.js View on Github external
app.use(koaRoute.post('/:repository/:pullRequestNumber', function* loadPullRequest(repository, pullRequestNumber) {
    const parts = busboyParse(this, {
        checkField: (name, value) => {
            if (name === 'githubAccessToken' && !value) {
                return new Error(401);
            }
        },
        checkFile: (fieldname, file, filename) => {
            if (path.extname(filename) !== '.jpg') {
                return new Error(400, 'Invalid jpg image');
            }
        },
    });

    let imageAsBuffer;
    let pullrequest;
    let part;
    while ((part = yield parts)) { // eslint-disable-line no-cond-assign
github TaleLin / lin-cms-koa-core / lib / extend.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/*');
    }
    // field指表单中的非文件
    const parts = parse(this, { autoFields: opts && opts.autoFields });
    let part;
    let totalSize = 0;
    const files: any[] = [];
    // tslint:disable-next-line:no-conditional-assignment
    while ((part = await parts()) != null) {
      if (part.length) {
        // arrays are busboy fields
      } else {
        if (!part.filename) {
          // user click `upload` before choose a file,
          // `part` will be file stream, but `part.filename` is empty
          // must handler this, such as log error.
          await sendToWormhole(part);
          continue;
        }
        // otherwise, it's a stream
github xiaokaike / magic-upload-image / server / koa-es6-server.js View on Github external
var upload = function * (next) {
  var parts = coParse(this)
  var part
  
  while (part = yield parts) {
    var url = '/upload/' + part.filename
    var stream = fs.createWriteStream(path.join(__dirname, '../public', url))
    part.pipe(stream)
    console.log('uploading %s -> %s', part.filename, stream.path)
  }

  this.body = {
    status: 'success',
    url: url
  }
}
github catamphetamine / webpack-react-redux-server-side-render-example / code / common / web server.js View on Github external
return new Promise((resolve, reject) =>
			{
				const file_name = Math.random().toString().slice(2)

				fs.existsAsync(path.join(folder, file_name)).then(exists =>
				{
					resolve(file_name)
				},
				error =>
				{
					reject(error)
				})
			})
		}

		const files = busboy(this)

		const file_names = []

		let file

		while (file = yield files)
		{
			if (log)
			{
				log.debug(`Uploading: ${file.filename}`)
			}

			if (!multiple_files && file_names.not_empty())
			{
				throw new Error(`Multiple files are being uploaded to a single file upload endpoint`)
			}

co-busboy

Busboy multipart parser as a yieldable

MIT
Latest version published 3 months ago

Package Health Score

76 / 100
Full package analysis

Popular co-busboy functions

Similar packages

    Popular JavaScript code snippets

    Find secure code to use in your application or website