{"id":14975729,"url":"https://github.com/larsdecker/gridfs-promise","last_synced_at":"2025-08-31T23:39:45.365Z","repository":{"id":28241757,"uuid":"117707930","full_name":"larsdecker/gridfs-promise","owner":"larsdecker","description":"GridFS-Promise Wrapper","archived":false,"fork":false,"pushed_at":"2024-09-06T06:27:09.000Z","size":448,"stargazers_count":3,"open_issues_count":6,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-01T06:23:13.897Z","etag":null,"topics":["database","gridfs","gridfs-stream","mongodb","mongoosejs","nestjs","nodejs","promise","typescript","wrapper"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/larsdecker.png","metadata":{"files":{"readme":"README.md","changelog":"History.md","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":"2018-01-16T16:15:50.000Z","updated_at":"2022-05-03T05:13:47.000Z","dependencies_parsed_at":"2024-02-11T18:29:48.192Z","dependency_job_id":"da9efe07-0960-446d-bc99-b7764f9cea6f","html_url":"https://github.com/larsdecker/gridfs-promise","commit_stats":{"total_commits":101,"total_committers":4,"mean_commits":25.25,"dds":"0.19801980198019797","last_synced_commit":"e795b88eabbb0b126691bc2c4e4bb1d208b2a5bd"},"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/larsdecker%2Fgridfs-promise","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/larsdecker%2Fgridfs-promise/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/larsdecker%2Fgridfs-promise/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/larsdecker%2Fgridfs-promise/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/larsdecker","download_url":"https://codeload.github.com/larsdecker/gridfs-promise/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238508815,"owners_count":19484208,"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":["database","gridfs","gridfs-stream","mongodb","mongoosejs","nestjs","nodejs","promise","typescript","wrapper"],"created_at":"2024-09-24T13:52:27.367Z","updated_at":"2025-02-12T16:31:57.193Z","avatar_url":"https://github.com/larsdecker.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gridfs-promise\n[![Known Vulnerabilities](https://snyk.io/test/github/larsdecker/gridfs-promise/badge.svg?targetFile=package.json)](https://snyk.io/test/github/larsdecker/gridfs-promise?targetFile=package.json)\n[![Build Status](https://travis-ci.org/larsdecker/gridfs-promise.svg?branch=master)](https://travis-ci.org/larsdecker/gridfs-promise)\n\nThis is a simple wrapper for the new MongoDB GridFSBucket-API (http://mongodb.github.io/node-mongodb-native/3.0/tutorials/gridfs/streaming/).\nThe old GridStore-API is now deprecated (http://mongodb.github.io/node-mongodb-native/3.0/tutorials/gridfs/gridstore/).\n\n## How to install\n\nThat is simple\n\n`npm install gridfs-promise`\n\n## Usage\n\n```js\nconst mongoOptions: MongoClientOptions = {\n  autoReconnect: true,\n  useNewUrlParser: true\n};\n\nlet gridFS = new GridFSPromise(\"test\", \"mongodb://localhost:27017/test\", mongoOptions, __dirname, \"attachments\");\ngridFS.getObject(\"59e085f272882d728e2fa4c2\").then((item) =\u003e {\n    console.log(item);\n}).catch((err) =\u003e {\n    console.error(err);\n});\n\n```\n\n\n## Methods\n\n### uploadFileString\n\nBy this method you can simple upload files by a base64 string \n\n```js\ngridFS.uploadFileString('R0lGODlhPQBEAPeoAJosM//AwO/AwHVYZ/z595kzAP/s7P+goOXMv8+fhw/v739/f+8PD98fH/8mJl+fn/9ZWb8/PzWlwv///6wWGbImAPgTEMImIN9gUFCEm/gDALULDN8PAD6atYdCTX9gUNKlj8wZAKUsAOzZz+UMAOsJAP/Z2ccMDA8PD/95eX5NWvsJCOVNQPtfX/8zM8+QePLl38MGBr8JCP+zs9myn/8GBqwpAP/GxgwJCPny78lzYLgjAJ8vAP9fX/+MjMUcAN8zM/9wcM8ZGcATEL+QePdZWf/29uc/P9cmJu9MTDImIN+/r7+/vz8/P8VNQGNugV8AAF9fX8swMNgTAFlDOICAgPNSUnNWSMQ5MBAQEJE3QPIGAM9AQMqGcG9vb6MhJsEdGM8vLx8fH98AANIWAMuQeL8fABkTEPPQ0OM5OSYdGFl5jo+Pj/+pqcsTE78wMFNGQLYmID4dGPvd3UBAQJmTkP+8vH9QUK+vr8ZWSHpzcJMmILdwcLOGcHRQUHxwcK9PT9DQ0O/v70w5MLypoG8wKOuwsP/g4P/Q0IcwKEswKMl8aJ9fX2xjdOtGRs/Pz+Dg4GImIP8gIH0sKEAwKKmTiKZ8aB/f39Wsl+LFt8dgUE9PT5x5aHBwcP+AgP+WltdgYMyZfyywz78AAAAAAAD///8AAP9mZv///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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V0HBRgxsvLThHn1oddQMrXj5DyAQgjEHSAJMWZwS3HPxT/QMbabI/iBCliMLEJKX2EEkomBAUCxRi42VDADxyTYDVogV+wSChqmKxEKCDAYFDFj4OmwbY7bDGdBhtrnTQYOigeChUmc1K3QTnAUfEgGFgAWt88hKA6aCRIXhxnQ1yg3BCayK44EWdkUQcBByEQChFXfCB776aQsG0BIlQgQgE8qO26X1h8cEUep8ngRBnOy74E9QgRgEAC8SvOfQkh7FDBDmS43PmGoIiKUUEGkMEC/PJHgxw0xH74yx/3XnaYRJgMB8obxQW6kL9QYEJ0FIFgByfIL7/IQAlvQwEpnAC7DtLNJCKUoO/w45c44GwCXiAFB/OXAATQryUxdN4LfFiwgjCNYg+kYMIEFkCKDs6PKAIJouyGWMS1FSKJOMRB/BoIxYJIUXFUxNwoIkEKPAgCBZSQHQ1A2EWDfDEUVLyADj5AChSIQW6gu10bE/JG2VnCZGfo4R4d0sdQoBAHhPjhIB94v/wRoRKQWGRHgrhGSQJxCS+0pCZbEhAAOw==', \"test.gif\", \"image/gif\", {}).then((result) =\u003e {\n    console.log(result);\n}).catch((error) =\u003e {\n    console.error(error);\n});\n```\n\n\n### getObject\n\nBy this method you will simple get the meta-object from the MongoDB as a Promise-Object.\nIf nothing found at the Database, then it will reject and the catch-block will be executed.\n\n```js\ngridFS.getObject(\"59e085f272882d728e2fa4c2\").then((item) =\u003e {\n    console.log(item);\n}).catch((err) =\u003e {\n    console.error(err);\n});\n```\n\n### getFile\n\nYou will get the file simple written to the filesystem directly from the Database.\nIf nothing found at the Database, then it will reject and the catch-block will be executed.\n\n```js\ngridFS.getFile(\"59e085f272882d728e2fa4c2\", \"test.gif\").then((item) =\u003e {\n    console.log(item);\n}).catch((err) =\u003e {\n    console.error(err);\n});\n```\n\n### getFileStream\n\nYou will get a GridFSBucketReadStream as Promise.\nIf nothing found at the Database, then it will reject and the catch-block will be executed.\n\nThis method is very useful, to stream the content directly to the user.\n\nFor example with express:\n```js\nreturn gridFs.getFileStream(req.params.id).then((item) =\u003e {\n                item\n                .once(\"error\", () =\u003e {\n                    return res.status(400).end();\n                }).pipe(res);\n        }).catch(() =\u003e res.status(500));\n```\n\n\n## Mongoose \u0026 Other MongoClient Connections\n\nYou can use you already existing MongoDB connection with the library. \n\n```typescript\n\nconst mongoDBConnection = await MongoClient.connect('mongodb://localhost:27017');\n\nconst test = new GridFSPromise('test');\ntest.CONNECTION = mongoDBConnection;\n\n\n```\n\n\n## Use GridFS Promise together with NestJS\n\nIt is really simple to use GridFS Promise together with NestJs.\n\nInstall the dependency via `npm install gridfs-promise --save`.\n\nIn the Module where you want to use GridFS create a simple Provider to Load the Lib\n\n```typescript\n// sample.module.ts\nproviders: [{\n    provide: GridFSPromise,\n    useFactory: async (configService: ConfigService) =\u003e {\n      return new GridFSPromise(configService.getString('DB_NAME'), configService.getString('DB_URL'));\n    },\n    inject: [ConfigService],\n  }]\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flarsdecker%2Fgridfs-promise","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flarsdecker%2Fgridfs-promise","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flarsdecker%2Fgridfs-promise/lists"}