{"id":29867088,"url":"https://github.com/junruchen/egg-obs","last_synced_at":"2025-07-30T13:19:17.056Z","repository":{"id":57220669,"uuid":"196003467","full_name":"junruchen/egg-obs","owner":"junruchen","description":"华为云 OBS，针对 Egg.js 开发","archived":false,"fork":false,"pushed_at":"2023-05-06T06:16:31.000Z","size":322,"stargazers_count":3,"open_issues_count":2,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-06-30T03:49:19.777Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/junruchen.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":"2019-07-09T12:24:01.000Z","updated_at":"2022-09-20T06:14:27.000Z","dependencies_parsed_at":"2022-08-29T04:01:44.772Z","dependency_job_id":null,"html_url":"https://github.com/junruchen/egg-obs","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/junruchen/egg-obs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junruchen%2Fegg-obs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junruchen%2Fegg-obs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junruchen%2Fegg-obs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junruchen%2Fegg-obs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/junruchen","download_url":"https://codeload.github.com/junruchen/egg-obs/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junruchen%2Fegg-obs/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267847451,"owners_count":24154195,"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","status":"online","status_checked_at":"2025-07-30T02:00:09.044Z","response_time":70,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":[],"created_at":"2025-07-30T13:19:16.152Z","updated_at":"2025-07-30T13:19:17.048Z","avatar_url":"https://github.com/junruchen.png","language":"JavaScript","readme":"# egg-obs\n\n[![NPM version][npm-image]][npm-url]\n[![build status][travis-image]][travis-url]\n[![Test coverage][codecov-image]][codecov-url]\n[![David deps][david-image]][david-url]\n[![Known Vulnerabilities][snyk-image]][snyk-url]\n[![npm download][download-image]][download-url]\n\n[npm-image]: https://img.shields.io/npm/v/egg-obs.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/egg-obs\n[travis-image]: https://img.shields.io/travis/eggjs/egg-obs.svg?style=flat-square\n[travis-url]: https://travis-ci.org/eggjs/egg-obs\n[codecov-image]: https://img.shields.io/codecov/c/github/eggjs/egg-obs.svg?style=flat-square\n[codecov-url]: https://codecov.io/github/eggjs/egg-obs?branch=master\n[david-image]: https://img.shields.io/david/eggjs/egg-obs.svg?style=flat-square\n[david-url]: https://david-dm.org/eggjs/egg-obs\n[snyk-image]: https://snyk.io/test/npm/egg-obs/badge.svg?style=flat-square\n[snyk-url]: https://snyk.io/test/npm/egg-obs\n[download-image]: https://img.shields.io/npm/dm/egg-obs.svg?style=flat-square\n[download-url]: https://npmjs.org/package/egg-obs\n[OBS](https://support.huaweicloud.com/obs/index.html) plugin for egg\n\n## Install\n\n```bash\n$ npm i egg-obs --save\n```\n\n## Configuration\n\n```js\n// config/plugin.js\nexports.obs = {\n  enable: true,\n  package: 'egg-obs',\n};\n```\n\n```js\n// config/config.default.js\nexports.obs = {\n  access_key_id: '',\n  secret_access_key: '',\n  server: '',\n  bucket: ''\n};\n```\n\nsee [config/config.default.js](config/config.default.js) for more detail.\n\n## Usage\n\n#### putObject({ key, imageProcess })\n#### getObject(options)\noptions参数说明：\n- Key\n- ImageProcess\n- SaveAsStream\n\n#### delObject({ key })\n#### setBucket(name)\n\nYou can require obs instance on app or ctx.\n\n```js\nconst path = require('path');\nconst Controller = require('egg').Controller;\n\nmodule.exports = class extends Controller {\n  // upload file\n  async upload() {\n    const { ctx } = this\n    const stream = await ctx.getFileStream()\n    const filename = Math.floor(Math.random() * 10000) + path.extname(stream.filename)\n    \n    try {\n      await ctx.obs.putObject({\n        key: filename,\n        body: stream\n      });\n      ctx.body = `/obs-image/${filename}`\n    } catch (error) {\n      ctx.body = error;\n      ctx.logger.error(new Error(error));\n    }\n  }\n\n  // get file\n  async getImage() {\n    const { ctx } = this\n    const objectname = ctx.params.objectname;\n    try {\n      const result = await ctx.obs.getObject({ Key: objectname })\n      if (result.CommonMsg.Status \u003c 300 \u0026\u0026 result.InterfaceResult) {\n        // 读取对象内容\n        const { ContentLength, Date, ETag, ContentType, Content } = result.InterfaceResult\n        ctx.status = 200\n        ctx.type = ContentType\n        ctx.etag = ETag\n        ctx.length = ContentLength\n        ctx.set('Date', Date)\n        ctx.body = Content\n      } else {\n        ctx.body = result.CommonMsg.Message\n      }\n    } catch (error) {\n      ctx.body = error\n      ctx.logger.error(new Error(error));\n    }\n  }\n};\n```\n\n## Questions \u0026 Suggestions\nIf upload blob file, `ctx.getFileStream()` will   prompt `[Invalid filename: blob]` error.\n\nUse `config.multipart = { fileExtensions: [''] }` to fix it.\n\nPlease open an issue [here](https://github.com/eggjs/egg/issues).\n\n## License\n\n[MIT](LICENSE)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjunruchen%2Fegg-obs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjunruchen%2Fegg-obs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjunruchen%2Fegg-obs/lists"}