{"id":45578875,"url":"https://github.com/allullc/nest-fastify-multer","last_synced_at":"2026-02-23T11:26:55.023Z","repository":{"id":57310019,"uuid":"416079504","full_name":"allullc/nest-fastify-multer","owner":"allullc","description":"The objective of this module is to provide a package with filters already prepared to work with 'fastify-multer'.","archived":false,"fork":false,"pushed_at":"2024-01-16T20:28:44.000Z","size":18,"stargazers_count":10,"open_issues_count":0,"forks_count":5,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-11-01T04:07:58.944Z","etag":null,"topics":["fastify","file","form-data","interceptor","multer","multipart","nest","upload","upload-file"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/allullc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2021-10-11T20:39:26.000Z","updated_at":"2024-12-26T11:47:49.000Z","dependencies_parsed_at":"2024-06-21T20:18:56.714Z","dependency_job_id":"3f53ee19-a0b0-4b73-b08b-16094f8646a0","html_url":"https://github.com/allullc/nest-fastify-multer","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/allullc/nest-fastify-multer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/allullc%2Fnest-fastify-multer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/allullc%2Fnest-fastify-multer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/allullc%2Fnest-fastify-multer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/allullc%2Fnest-fastify-multer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/allullc","download_url":"https://codeload.github.com/allullc/nest-fastify-multer/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/allullc%2Fnest-fastify-multer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29741485,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-23T07:44:07.782Z","status":"ssl_error","status_checked_at":"2026-02-23T07:44:07.432Z","response_time":90,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["fastify","file","form-data","interceptor","multer","multipart","nest","upload","upload-file"],"created_at":"2026-02-23T11:26:53.415Z","updated_at":"2026-02-23T11:26:55.008Z","avatar_url":"https://github.com/allullc.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nest-fastify-multer\n\n## Install\n```sh\nnpm i nest-fastify-multer\n```\n## External Dependency Packages\n\nBefore installing and using this package you must make sure you have `fastify-multer` installed.\n\n```sh\nnpm i fastify-multer\n```\nYou must configure this in the `main.js` of your Nest application.\n\n```js\nimport { NestFactory } from '@nestjs/core';\nimport {\n  FastifyAdapter,\n  NestFastifyApplication,\n} from '@nestjs/platform-fastify';\nimport { AppModule } from './app.module';\nimport { contentParser } from 'fastify-multer';\n\nasync function bootstrap() {\n  const app = await NestFactory.create\u003cNestFastifyApplication\u003e(\n    AppModule,\n    new FastifyAdapter()\n  );\n  await app.register(contentParser);\n  await app.listen(3000);\n}\n\nbootstrap()\n```\n\n## Usage\n\n```ts\nimport {\n  Body,\n  Controller,\n  Post,\n  Req, \n  UploadedFile,\n} from '@nestjs/common';\n\n// import the filters to use from the module.\nimport {\n  FastifyFileInterceptor,\n  FastifyFilesInterceptor,\n  FastifyFileFieldsInterceptor,\n} from 'nest-fastify-multer';\n\n// import multer to use your methods\nimport { diskStorage } from 'multer';\n\n@Controller('image')\nexport class ImageController {\n\n  @Post('uploadFile')\n  // use this interceptor to specify one file\n  @FastifyFileInterceptor(\n  // fileName\n    'avatar',\n  // here you can add any multer configuration.\n   {\n      storage: diskStorage({\n        destination: './upload/single', // path where the file will be downloaded\n        filename: editFileName, // here you can put your own function to edit multer file name when saving to local disk\n      }),\n      fileFilter: imageFileFilter, // here you can put your own function to filter the received files\n    }\n  )\n  uploadFile(\n    @Req() req: Request,\n    // use this param decorator to capture the file. The file type Express.Multer.File is used as this is used.\n    @UploadedFiles() file: Express.Multer.File,\n  ) {\n    return file;\n  }\n\n  @Post('uploadFiles')\n  // use this interceptor to specify more than one file\n  @FastifyFilesInterceptor(\n  // fileName\n    'avatar',\n  // maxCount  \n     1,\n  // here you can add any multer configuration.\n   {\n      storage: diskStorage({\n        destination: './upload/single', // path where the file will be downloaded\n        filename: editFileName, // here you can put your own function to edit multer file name when saving to local disk\n      }),\n      fileFilter: imageFileFilter, // here you can put your own function to filter the received files\n    }\n  )\n  uploadFiles(\n    @Req() req: Request,\n    // use this param decorator to capture the files. The file type Express.Multer.File is used as this is used.\n    @UploadedFile() files: Express.Multer.File[],\n  ) {\n    return files;\n  }\n  \n  @Post('uploadFileFields')\n  // use this interceptor to specify more than one field containing files\n  @FastifyFileFieldsInterceptor(\n  // specify here the array of field name and maximum number of files allowed in this field.  \n    [{ name: 'avatar', maxCount: 1 }, { name: 'background', maxCount: 1 }],\n  // here you can add any multer configuration.\n   {\n      storage: diskStorage({\n        destination: './upload/single', // path where the file will be downloaded\n        filename: editFileName, // here you can put your own function to edit multer file name when saving to local disk\n      }),\n      fileFilter: imageFileFilter, // here you can put your own function to filter the received files\n    }\n  )\n  uploadFileFields(\n    @Req() req: Request,\n    // use this param decorator to capture the files. The file type Express.Multer.File is used as this is used.\n    @UploadedFile() files: { avatar?: Express.Multer.File[], background?: Express.Multer.File[] },\n  ) {\n    return files;\n  }\n\n}\n```\nA possible implementation of the `editFileName` and `imageFileFilter` methods is provided.\n\n```ts\nimport { extname } from 'path';\n\nexport const editFileName = (\n  req: Request,\n  file: Express.Multer.File,\n  callback\n) =\u003e {\n  const name = file.originalname.split('.')[0];\n  const fileExtName = extname(file.originalname);\n  const randomName = Array(4)\n    .fill(null)\n    .map(() =\u003e Math.round(Math.random() * 16).toString(16))\n    .join('');\n  callback(null, `${name}-${randomName}${fileExtName}`);\n};\n\nexport const imageFileFilter = (\n  req: Request,\n  file: Express.Multer.File,\n  callback\n) =\u003e {\n  if (!file.originalname.match(/\\.(jpg|jpeg|png|gif)$/)) {\n    return callback(new Error('Only image files are allowed!'), false);\n  }\n  callback(null, true);\n};\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fallullc%2Fnest-fastify-multer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fallullc%2Fnest-fastify-multer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fallullc%2Fnest-fastify-multer/lists"}