Skip to content

Instantly share code, notes, and snippets.

@devarajchidambaram
Created November 26, 2019 10:39
Show Gist options
  • Save devarajchidambaram/02db3b690e0809a2f4459a89e3631c78 to your computer and use it in GitHub Desktop.
Save devarajchidambaram/02db3b690e0809a2f4459a89e3631c78 to your computer and use it in GitHub Desktop.
Minio object storage server
var Minio = require('minio')
// Instantiate the minio client with the endpoint
// and access keys as shown below.
var minioClient = new Minio.Client({
endPoint: 'localhost',
port: 9000,
useSSL: false,
accessKey: '0OPKIKKR058HTBYXV2JA',
secretKey: 'oT7jT9a0u5UTWoNW5nU+wMdE3lfRtwL5B0FZVRVu'
});
// File that needs to be uploaded.
var file = './samples/100MB.bin'
// Make a bucket called europetrip.
// minioClient.makeBucket('birds', function(err) {
// if (err) { console.log(err) }
// console.log('Bucket created successfully....')
var metaData = {
'Content-Type': 'image/jpeg',
}
console.log('process id==', process.pid)
// Bucket name file name Greater than 5 mb files are uploaded as stream..
// minioClient.fPutObject('birds', '1GB.bin', file, metaData, function(err, etag) {
// const fs = require('fs')
// const readStream = fs.createReadStream(file)
// minioClient.putObject('birds', '1GB.bin', readStream, function(err, etag) {
// if (err) return console.log(err)
// console.log('File uploaded successfully.' + etag)
// });
//COPY
var conds = new Minio.CopyConditions()
conds.setMatchETag('40d899c7250447611bee6532126846a0-1')
// minioClient.copyObject('birds', '1.jpg', '/images/test', conds, function(err, data) {
// if (err) {
// throw err
// }
// console.log("Successfully copied the object:")
// console.log("etag = " + data.etag + ", lastModified = " + data.lastModified)
// })
// minioClient.statObject('birds', '1.jpg', function(err, stat) {
// if (err) {
// return console.log(err)
// }
// console.log(stat)
// })
//Read File
// var size = 0
// minioClient.getObject('birds', '1.jpg', function(err, dataStream) {
// if (err) {
// return console.log(err)
// }
// dataStream.on('data', function(chunk) {
// size += chunk.length
// })
// dataStream.on('end', function() {
// console.log('End. Total size = ' + size)
// })
// dataStream.on('error', function(err) {
// console.log(err)
// })
// })
//Partially uploaded data
/**
var Stream = minioClient.listIncompleteUploads('birds', '', true)
var data= ''
Stream.on('data', function (obj) {
console.log(obj)
data += obj;
})
Stream.on('end', function () {
console.log('obj', data)
console.log('End')
})
Stream.on('error', function (err) {
console.log(err)
})
**/
// minioClient.listBuckets(function(err, buckets) {
// if (err) return console.log(err)
// console.log('buckets :', buckets)
// })
// });
//Exists
// minioClient.bucketExists("birds", function(err, exists){
// if(err) throw err;
// console.log('exists', exists)
// })
//List of objects
// var stream = minioClient.listObjects('birds', '', true)
// stream.on('data', function (obj) {
// console.log('obj==>' ,obj)
// })
// stream.on('error', function (err) {
// console.log(err)
// })
//Pre signeed URL
minioClient.presignedUrl('GET', 'birds', '1.jpg', 24*60*60, function(err, presignedUrl) {
if (err) return console.log(err)
console.log(presignedUrl)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment