{"id":17944803,"url":"https://github.com/aryaman1706/cloudinary-multer","last_synced_at":"2025-07-05T05:01:44.186Z","repository":{"id":57200809,"uuid":"316899740","full_name":"Aryaman1706/cloudinary-multer","owner":"Aryaman1706","description":"A custom multer store to upload assets to cloudinary.","archived":false,"fork":false,"pushed_at":"2020-12-01T06:27:33.000Z","size":174,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-15T21:43:50.673Z","etag":null,"topics":["cloudinary","cloudinary-library","javascript","multer","multer-storage","nodejs","npm","npm-package","upload-file"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/cloudinary-multer","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/Aryaman1706.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}},"created_at":"2020-11-29T07:37:15.000Z","updated_at":"2022-06-08T15:11:35.000Z","dependencies_parsed_at":"2022-09-16T15:10:55.115Z","dependency_job_id":null,"html_url":"https://github.com/Aryaman1706/cloudinary-multer","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aryaman1706%2Fcloudinary-multer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aryaman1706%2Fcloudinary-multer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aryaman1706%2Fcloudinary-multer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aryaman1706%2Fcloudinary-multer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Aryaman1706","download_url":"https://codeload.github.com/Aryaman1706/cloudinary-multer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245328367,"owners_count":20597407,"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":["cloudinary","cloudinary-library","javascript","multer","multer-storage","nodejs","npm","npm-package","upload-file"],"created_at":"2024-10-29T06:05:09.480Z","updated_at":"2025-03-24T18:32:21.972Z","avatar_url":"https://github.com/Aryaman1706.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Cloudinary-Multer\n\n[cloudinary-multer](https://www.npmjs.com/package/cloudinary-multer)\n\nA custom multer storage engine to upload assets to cloudinary.\n\n### Installation\n\ncloudinary-multer can be installed easily via [npm](https://www.npmjs.com/)\n\n`npm install cloudinary-multer`\n\n## Usage\n\n#### Cloudinary Configuration\n\n```javascript\nconst cloudinary = require(\"cloudinary\").v2;\n\ncloudinary.config({\n  cloud_name: \"XXXXXXXXX\",\n  api_key: \"XXXXXXXXX\",\n  api_secret: \"XXXXXXXXX\",\n});\n```\n\n#### Storage Engine\n\n```javascript\nconst cloudinaryStorage = require(\"cloudinary-multer\");\n\nconst storage = cloudinaryStorage({\n  cloudinary: cloudinary,\n});\n\nconst upload = multer({\n  storage: storage,\n});\n```\n\n### Options\n\nCustom Storage Engine has 4 options namely:-\n\n1. `cloudinary` (required)\n\nThe cloudinary library instance to be used for uploading assets.\nConfiguration options can be found [here](https://cloudinary.com/documentation/node_integration#configuration)\n\n**Example**:-\n\n```javascript\ncloudinary.config({\n  cloud_name: \"XXXXXXXXX\",\n  api_key: \"XXXXXXXXX\",\n  api_secret: \"XXXXXXXXX\",\n});\n```\n\n2. `validator` (optional)\n\nSince `req.body` is not available prior to the multer middleware, it seemed to be a good idea to include a validator to validate the request body.\n`validator` is supposed to be function that would return false for valid body and an error message/true otherwise.\n\n**The order of fields in req.body is very important. Make sure that the field of type \"file\" must be last. All other fields that need to be validated should be on top.**\n\n**Example**:-\n\n```javascript\nconst validator = (body) =\u003e {\n  /**\n   * req.body would be passed as a parameter(body) here\n   * Order of req.body is very important for validating.\n   * Make sure that file is the LAST FIELD in req.body.\n   * example:-\n        req.body: {\n            email: \"test_email@mail.com\",\n            username: \"test username\"\n            file: {FILE}\n        }\n   */\n  const schema = Joi.object({\n    email: Joi.string().email().required(),\n    username: Joi.string().max(40).required(),\n  });\n  const { error } = schema.validate(body);\n  if (error) return error;\n  return false;\n};\n```\n\n3. `uploadOptions` (optional)\n\nThese are the options that needed to be applied to upload methord in cloudinary.\nKnow that the methord used under the hood is `upload_stream`.\nMore information can be found [here](https://www.npmjs.com/package/cloudinary) and [here](https://cloudinary.com/documentation/image_upload_api_reference).\n\n4. `destroyOptions` (optional)\n\nThese are the options that needed to be applied to upload methord in cloudinary.\nMore information can be found [here](https://cloudinary.com/documentation/image_upload_api_reference#destroy_method).\n\n### Usage in Route\n\n```javascript\napp.post(\"/upload\", upload.single(\"file\"), async (req, res) =\u003e {});\n```\n\n**A simple complete example of the same could be found [here](https://github.com/Aryaman1706/cloudinary-multer/blob/master/example/server.js)**.\n\n## Working\n\ncloudinary-multer a simple custom storage engine to directly upload assets to [cloudinary](https://cloudinary.com/).\n`_handleFile` function in multer storage engine gives the file data in form of a readable stream (`file.stream`).\nThis file stream is then uploaded directly to cloudinary if the validation is successfull.\nUploading the stream directly is a great advantage as the file is not stored in your disk/server unlike traditional diskStorage(stores file in your disk) and memoryStorage(stores file as buffer in server memory).\n\n## Contributing\n\nFeel free to report a bug, suggest a change etc. You are welcome to raise an issue and/or create a pull request.\nBefore making any major upgrade, kindly raise an issue to discuss further.\nMake sure to run `npm run format` and `npm run lint` before commiting your changes/generating a PR.\n\n## Read Further\n\n- [Multer npm](https://www.npmjs.com/package/multer)\n- [Multer Custom Storage Engine](https://github.com/expressjs/multer/blob/master/StorageEngine.md)\n- [Cloudinary Documentation](https://cloudinary.com/documentation)\n- [Cloudinary npm](https://www.npmjs.com/package/cloudinary)\n\n## License\n\n[MIT](https://opensource.org/licenses/MIT)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faryaman1706%2Fcloudinary-multer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faryaman1706%2Fcloudinary-multer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faryaman1706%2Fcloudinary-multer/lists"}