{"id":13798837,"url":"https://github.com/dominhhai/koa-busboy","last_synced_at":"2025-04-12T00:31:45.757Z","repository":{"id":49899804,"uuid":"89134641","full_name":"dominhhai/koa-busboy","owner":"dominhhai","description":"Upload files with Busboy","archived":false,"fork":false,"pushed_at":"2023-06-10T05:40:44.000Z","size":12,"stargazers_count":32,"open_issues_count":7,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-21T09:36:02.655Z","etag":null,"topics":["busboy","koa-busboy","koa-middleware","koa2","middleware","multipart","upload-file"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/koa-busboy","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dominhhai.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-04-23T10:43:46.000Z","updated_at":"2024-09-17T20:18:13.000Z","dependencies_parsed_at":"2024-06-18T18:28:26.334Z","dependency_job_id":"195a354e-1956-45ed-991f-d524efa865f8","html_url":"https://github.com/dominhhai/koa-busboy","commit_stats":{"total_commits":16,"total_committers":6,"mean_commits":"2.6666666666666665","dds":0.5625,"last_synced_commit":"52979d1f902a86a1c74b75b7819cfe4089685fd4"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dominhhai%2Fkoa-busboy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dominhhai%2Fkoa-busboy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dominhhai%2Fkoa-busboy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dominhhai%2Fkoa-busboy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dominhhai","download_url":"https://codeload.github.com/dominhhai/koa-busboy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248501323,"owners_count":21114652,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["busboy","koa-busboy","koa-middleware","koa2","middleware","multipart","upload-file"],"created_at":"2024-08-04T00:00:55.057Z","updated_at":"2025-04-12T00:31:45.517Z","avatar_url":"https://github.com/dominhhai.png","language":"JavaScript","funding_links":[],"categories":["仓库"],"sub_categories":["中间件"],"readme":"# koa-busboy\nA koa's middleware for handling multipart form.\nNote that, this middleware supports `Koa v2` only.\n\n## Installation\n\n```\n$ npm i -S koa-busboy\n```\n\n## Usage\n`koa-busboy` will adds all text `fields` to `ctx.request.body` object and uploaded `files` to `ctx.request.files` array.\n\nTo create middleware, simply call the module function with custom config options as following:\n\n```javascript\nconst busboy = require('koa-busboy')\nconst uploader = busboy(options)\n```\n\nWhile, `options` is same as original [busboy](https://github.com/mscdex/busboy#api) module.\n\nHowever, you can specify the following options also.\n* **dest** - _string_ - The folder to save uploaded files (Default: system temp folder - `os.tmpdir()`).\n\n* **fnDestFilename** - _function_ - The function that defines the final filename which saved on `dest` folder. The `fnDestFilename(fieldname, filename)` function will return the name of file which be saved on disk. While `fieldname` is your uploaded field's name and `filename` is your uploaded file's name. (Default: `(fieldname, filename) =\u003e Date.now() + fieldname + filename`)\n\n* **acceptMimeTypes** - _Array_ - A list of [mimetypes](https://www.iana.org/assignments/media-types/media-types.xhtml) that are accepted, default is to accept all.\n\n### Example\n```javascript\nconst busboy = require('koa-busboy')\nconst koaRouter = require('koa-router')\n\nconst uploader = busboy({\n  dest: './upload' // default is system temp folder (`os.tmpdir()`)\n  fnDestFilename: (fieldname, filename) =\u003e uuid() + filename,\n  acceptMimeTypes: ['image/gif', 'image/jpeg'] //only gif and jpeg files are uploded\n})\nconst router = koaRouter()\n\nrouter.post('/upload', uploader, async ctx =\u003e {\n  // fields\n  // text fields is add to ctx.request.body object\n  let { name } = ctx.request.body\n  // files\n  // uploaded files is add to ctx.request.files array\n  let fileReadStream = ctx.request.files[0]\n})\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdominhhai%2Fkoa-busboy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdominhhai%2Fkoa-busboy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdominhhai%2Fkoa-busboy/lists"}