-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminioStorage.js
54 lines (48 loc) · 1.76 KB
/
minioStorage.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
const http = require('http')
const Minio = require('minio')
function MinioCustomStorage() { }
MinioCustomStorage.prototype.getMinioClient = function getMinioClient(token, cb) {
const minioClient = new Minio.Client({
endPoint: 'localhost',
port: 9000,
accessKey: "admin",
secretKey: "ChangezMoi",
useSSL: false
})
cb(null, minioClient)
}
MinioCustomStorage.prototype._handleFile = function _handleFile(req, file, cb) {
this.getMinioClient("", (err, minioClient) => {
try {
if (err) {
res.json({ 'success': false, 'message': err })
}
var originalname = file.originalname.split(' ');
const fileName = originalname.join('_');
let used = process.memoryUsage()
for (let key in used) {
console.log(`${key} ${Math.round(used[key] / 1024 / 1024 * 100) / 100} MB`)
}
minioClient.putObject(req.params.bucket, fileName, file.stream, (err, objInfo) => {
if (err) {
console.log(err)
return cb(err, {})
}
let used = process.memoryUsage()
for (let key in used) {
console.log(`${key} ${Math.round(used[key] / 1024 / 1024 * 100) / 100} MB`)
}
return cb(null, {})
});
} catch (err) {
console.log(err)
return cb(err, {})
}
})
}
MinioCustomStorage.prototype._removeFile = function _removeFile(req, file, cb) {
fs.unlink(file.path, cb)
}
module.exports = function (opts) {
return new MinioCustomStorage(opts)
}