diff options
author | Christoph (Sheogorath) Kern | 2018-01-23 11:43:24 +0100 |
---|---|---|
committer | GitHub | 2018-01-23 11:43:24 +0100 |
commit | eec2318bda29f6633f9c9b4198e507959fa12d46 (patch) | |
tree | f6a8f315a1852850c0e6196ccf1b8dd9e19e55cb /lib/web | |
parent | 7de6e3211f797ed9e9e5ca3d52181f77abf030d0 (diff) | |
parent | 2c780f53df73a0ba1f13109213d95df7f32cbd8a (diff) |
Merge pull request #506 from erasys/minio
Add support for minio
Diffstat (limited to 'lib/web')
-rw-r--r-- | lib/web/imageRouter.js | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/web/imageRouter.js b/lib/web/imageRouter.js index bebab302..b17cccbd 100644 --- a/lib/web/imageRouter.js +++ b/lib/web/imageRouter.js @@ -73,6 +73,40 @@ imageRouter.post('/uploadimage', function (req, res) { }) }) break + + case 'minio': + var utils = require('../utils') + var Minio = require('minio') + var minioClient = new Minio.Client({ + endPoint: config.minio.endPoint, + port: config.minio.port, + secure: config.minio.secure, + accessKey: config.minio.accessKey, + secretKey: config.minio.secretKey + }) + fs.readFile(files.image.path, function (err, buffer) { + if (err) { + logger.error(err) + res.status(500).end('upload image error') + return + } + + var key = path.join('uploads', path.basename(files.image.path)) + var protocol = config.minio.secure ? 'https' : 'http' + + minioClient.putObject(config.s3bucket, key, buffer, buffer.size, utils.getImageMimeType(files.image.path), function (err, data) { + if (err) { + logger.error(err) + res.status(500).end('upload image error') + return + } + res.send({ + link: `${protocol}://${config.minio.endPoint}:${config.minio.port}/${config.s3bucket}/${key}` + }) + }) + }) + break + case 'imgur': default: imgur.setClientId(config.imgur.clientID) |