Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alincode/koa-gcs
https://github.com/alincode/koa-gcs
Last synced: 11 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/alincode/koa-gcs
- Owner: alincode
- Created: 2019-07-24T04:03:42.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-12-24T12:44:14.000Z (about 4 years ago)
- Last Synced: 2024-12-17T00:53:04.461Z (19 days ago)
- Language: JavaScript
- Size: 21.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Koa GCS
Koa GCS middleware
![npm downloads](https://img.shields.io/npm/dt/koa-gcs.svg)
[![Dependency Status](https://img.shields.io/david/alincode/koa-gcs.svg?style=flat)](https://david-dm.org/alincode/koa-gcs)
[![NPM version][npm-image]][npm-url]### Maintainers
- [alincode](https://github.com/alincode) - **AILIN LIOU** (author)
## Installation and Usage
```
npm install koa-gcs --save
``````js
const Koa = require('koa')
const cors = require('@koa/cors')
const Router = require('@koa/router')
const KoaGCS = require('koa-gcs')const app = new Koa()
const router = new Router()const config = {
gcs: {
bucket: 'your-backet-name',
},
maxFileSizeLimit: 5 * 1024 * 1024, // 5mb
storageOption: {
projectId: 'your-gcp-project-id',
},
image: {
thumbnail: true,
},
}router.post('/upload', koaGCS.multer.single('file'), async (ctx) => {
const file = await koaGCS.sendUploadToGCS(ctx.req.file, 'users')
const {
cloudStoragePublicUrl,
mimetype,
fieldname,
originalname,
encoding,
size,
cloudStorageObject,
thumbnailUrl,
} = file
const { width, height } = ctx.req.bodyctx.body = {
thumbnail: thumbnailUrl,
url: cloudStoragePublicUrl,
width,
height,
mimeType: mimetype,
}
})
app.use(cors())
app.use(router.routes())
app.use(router.allowedMethods())
app.listen(3000)
```### example
```
npm run demo
```### default config
```js
const defaultConfig = {
gcs: {
bucket: 'your-bucket-name',
},
maxFileSizeLimit: 5 * 1024 * 1024, // 5mb
storageOption: {
keyFilename: path.join(__dirname, './firebase-serviceAccountKey.json'),
projectId: 'your-gcp-project-id',
},
image: {
resize: '800x',
quality: 90,
thumbnail: false,
},
}
```### kill server when seeing “EADDRINUSE: address already in use”
```
Error: listen EADDRINUSE: address already in use :::3000
at Server.setupListenHandle [as _listen2] (net.js:1228:14)
at listenInCluster (net.js:1276:12)
at Server.listen (net.js:1364:7)
``````
lsof -i tcp:3000
kill -9 ?????
```### related projects
- [imagemagick-stream](https://github.com/eivindfjeldstad/imagemagick-stream)
- [koa-multer](https://github.com/koa-modules/multer)
- [stream](https://github.com/juliangruber/stream)### License
MIT © [alincode](https://github.com/alincode)
[npm-url]: https://npmjs.org/package/koa-gcs
[npm-image]: http://img.shields.io/npm/v/koa-gcs.svg