JavaScript Client API Reference
import*asMiniofrom'minio'constminioClient=newMinio.Client({endPoint:'play.min.io',port:9000,useSSL:true,accessKey:'Q3AM3UQ867SPQQA43P2F',secretKey:'zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG',})import*asMiniofrom'minio'consts3Client=newMinio.Client({endPoint:'s3.amazonaws.com',accessKey:'YOUR-ACCESSKEYID',secretKey:'YOUR-SECRETACCESSKEY',})new Minio.Client ({endPoint, port, useSSL, accessKey, secretKey, region, transport, sessionToken, partSize})
new Minio.Client ({endPoint, port, useSSL, accessKey, secretKey, region, transport, sessionToken, partSize}) |
| Initializes a new client object. |
Parameters
| Param | Type | Description |
|---|---|---|
endPoint | string | endPoint is a host name or an IP address. |
port | number | TCP/IP port number. This input is optional. Default value set to 80 for HTTP and 443 for HTTPs. |
useSSL | bool | If set to true, https is used instead of http. Default is true. |
accessKey | string | accessKey is like user-id that uniquely identifies your account. |
secretKey | string | secretKey is the password to your account. |
sessionToken | string | Set this value to provide x-amz-security-token (AWS S3 specific). (Optional) |
region | string | Set this value to override region cache. (Optional) |
transport | string | Set this value to pass in a custom transport. (Optional) |
partSize | number | Set this value to override default part size of 64MB for multipart uploads. (Optional) |
pathStyle | bool | Set this value to override default access behavior (path) for non AWS endpoints. Default is true. (Optional) |
transportAgent | Agent | Set this value to provide a custom HTTP(s) agent to handle timeouts, TLS handling, and low-level socket configurations. (Optional) |
Example
import*asMiniofrom'minio'constminioClient=newMinio.Client({endPoint:'play.min.io',port:9000,useSSL:true,accessKey:'Q3AM3UQ867SPQQA43P2F',secretKey:'zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG',})import*asMiniofrom'minio'consts3Client=newMinio.Client({endPoint:'s3.amazonaws.com',accessKey:'YOUR-ACCESSKEYID',secretKey:'YOUR-SECRETACCESSKEY',})import*asMiniofrom'minio'consts3Client=newMinio.Client({endPoint:'s3.amazonaws.com',accessKey:'YOUR-TEMP-ACCESSKEYID',secretKey:'YOUR-TEMP-SECRETACCESSKEY',sessionToken:'YOUR-TEMP-SESSIONTOKEN',})import*asMiniofrom'minio'import*asfsfrom'fs'import*ashttpsfrom'https'consts3Client=newMinio.Client({endPoint:'play.min.io',port:9000,useSSL:true,accessKey:'Q3AM3UQ867SPQQA43P2F',secretKey:'zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG',transportAgent:newhttps.Agent({timeout:10000,ca:fs.readFileSync('path/to/ca.cert'),cert:fs.readFileSync('path/to/public.cert'),key:fs.readFileSync('path/to/secret.key'),keepAlive:false,}),})Creates a new bucket.
Parameters
| Param | Type | Description |
|---|---|---|
bucketName | string | Name of the bucket. |
region | string | Region where the bucket is created. This parameter is optional. Default value is us-east-1. |
makeOpts | object | Options to create a bucket. e.g{ObjectLocking:true} (Optional) |
Example
awaitminioClient.makeBucket('mybucket','us-east-1')console.log('Bucket created successfully in "us-east-1".')Example 1Create a bucket with object locking enabled.
minioClient.makeBucket('mybucket','us-east-1',{ObjectLocking:true},function(err){if(err)returnconsole.log('Error creating bucket with object lock.',err)console.log('Bucket created successfully in "us-east-1" and enabled object lock')})Lists all buckets.
Parameters
NIL
Returns Array of Objects with the format:-
| Param | Type | Description |
|---|---|---|
bucket.name | string | bucket name |
bucket.creationDate | Date | date when bucket was created. |
Example
Please refer to:list-buckets.mjs
try{constbuckets=awaitminioClient.listBuckets()console.log('Success',buckets)}catch(err){console.log(err.message)}Checks if a bucket exists.
Parameters
| Param | Type | Description |
|---|---|---|
bucketName | string | Name of the bucket. |
Example
constexists=awaitminioClient.bucketExists('mybucket')if(exists){returnconsole.log('Bucket exists.')}Removes a bucket.
Parameters
| Param | Type | Description |
|---|---|---|
bucketName | string | Name of the bucket. |
callback(err) | function | err isnull if the bucket is removed successfully. If no callback is passed, aPromise is returned. |
Example
try{awaitminioClient.removeBucket('mybucket')console.log('Bucket removed successfully.')}catch(err){console.log('unable to remove bucket.')}Lists all objects in a bucket.
Parameters
| Param | Type | Description |
|---|---|---|
bucketName | string | Name of the bucket. |
prefix | string | The prefix of the objects that should be listed (optional, default''). |
recursive | bool | true indicates recursive style listing andfalse indicates directory style listing delimited by ‘/’. (optional, defaultfalse). |
listOpts | object | query params to list object which can have{IncludeVersion: _bool_ } (optional) |
Return Value
| Param | Type | Description |
|---|---|---|
stream | Stream | Stream emitting the objects in the bucket. |
The object is of the format:
| Param | Type | Description |
|---|---|---|
obj.name | string | name of the object. |
obj.prefix | string | name of the object prefix. |
obj.size | number | size of the object. |
obj.etag | string | etag of the object. |
obj.versionId | string | versionId of the object. |
obj.isDeleteMarker | boolean | true if it is a delete marker. |
obj.lastModified | Date | modified time stamp. |
Example
constdata=[]conststream=minioClient.listObjects('mybucket','',true)stream.on('data',function(obj){data.push(obj)})stream.on('end',function(){console.log(data)})stream.on('error',function(err){console.log(err)})Example1To get Object versions
constdata=[]conststream=minioClient.listObjects('mybucket','',true,{IncludeVersion:true})stream.on('data',function(obj){data.push(obj)})stream.on('end',function(){console.log(data)})stream.on('error',function(err){console.log(err)})Lists all objects in a bucket using S3 listing objects V2 API
Parameters
| Param | Type | Description |
|---|---|---|
bucketName | string | Name of the bucket. |
prefix | string | The prefix of the objects that should be listed (optional, default''). |
recursive | bool | true indicates recursive style listing andfalse indicates directory style listing delimited by ‘/’. (optional, defaultfalse). |
startAfter | string | Specifies the object name to start after when listing objects in a bucket. (optional, default''). |
Return Value
| Param | Type | Description |
|---|---|---|
stream | Stream | Stream emitting the objects in the bucket. |
The object is of the format:
| Param | Type | Description |
|---|---|---|
obj.name | string | name of the object. |
obj.prefix | string | name of the object prefix. |
obj.size | number | size of the object. |
obj.etag | string | etag of the object. |
obj.lastModified | Date | modified time stamp. |
Example
conststream=minioClient.listObjectsV2('mybucket','',true,'')stream.on('data',function(obj){console.log(obj)})stream.on('error',function(err){console.log(err)})Lists all objects and their metadata in a bucket using S3 listing objects V2 API
Parameters
| Param | Type | Description |
|---|---|---|
bucketName | string | Name of the bucket. |
prefix | string | The prefix of the objects that should be listed (optional, default''). |
recursive | bool | true indicates recursive style listing andfalse indicates directory style listing delimited by ‘/’. (optional, defaultfalse). |
startAfter | string | Specifies the object name to start after when listing objects in a bucket. (optional, default''). |
Return Value
| Param | Type | Description |
|---|---|---|
stream | Stream | Stream emitting the objects in the bucket. |
The object is of the format:
| Param | Type | Description |
|---|---|---|
obj.name | string | name of the object. |
obj.prefix | string | name of the object prefix. |
obj.size | number | size of the object. |
obj.etag | string | etag of the object. |
obj.lastModified | Date | modified time stamp. |
obj.metadata | object | metadata of the object. |
Example
conststream=minioClient.extensions.listObjectsV2WithMetadata('mybucket','',true,'')stream.on('data',function(obj){console.log(obj)})stream.on('error',function(err){console.log(err)})Lists partially uploaded objects in a bucket.
Parameters
| Param | Type | Description |
|---|---|---|
bucketName | string | Name of the bucket. |
prefix | string | Prefix of the object names that are partially uploaded. (optional, default'') |
recursive | bool | true indicates recursive style listing andfalse indicates directory style listing delimited by ‘/’. (optional, defaultfalse). |
Return Value
| Param | Type | Description |
|---|---|---|
stream | Stream | Emits objects of the format listed below: |
| Param | Type | Description |
|---|---|---|
part.key | string | name of the object. |
part.uploadId | string | upload ID of the object. |
part.size | Integer | size of the partially uploaded object. |
Example
constStream=minioClient.listIncompleteUploads('mybucket','',true)Stream.on('data',function(obj){console.log(obj)})Stream.on('end',function(){console.log('End')})Stream.on('error',function(err){console.log(err)})Get Versioning state of a Bucket
Parameters
| Param | Type | Description |
|---|---|---|
bucketName | string | Name of the bucket. |
Example
constversionInfo=awaitminioClient.getBucketVersioning('bucketname')console.log('Success ',versionInfo)Set Versioning state on a Bucket
Parameters
| Param | Type | Description |
|---|---|---|
bucketName | string | Name of the bucket. |
versioningConfig | object | Versioning Configuration e.g:{Status:"Enabled"} |
Example
constversioningConfig={Status:'Enabled'}awaitminioClient.setBucketVersioning('bucketname',versioningConfig)Set replication config on a Bucket
Parameters
| Param | Type | Description |
|---|---|---|
bucketName | string | Name of the bucket. |
replicationConfig | object | replicationConfig Configuration as a JSON Object |
Example
constarnFromMcCli='arn:minio:replication::b22d653b-e4fb-4c5d-8140-7694c8e72ed4:dest-bucket'constreplicationConfig={role:arnFromMcCli,rules:[{ID:'cisea130mbms6splbmg0',Status:'Enabled',Priority:1,DeleteMarkerReplication:{Status:'Enabled'},DeleteReplication:{Status:'Enabled'},Destination:{Bucket:'arn:aws:s3:::dest-bucket',StorageClass:'REDUCED_REDUNDANCY',},SourceSelectionCriteria:{ReplicaModifications:{Status:'Enabled'}},Filter:{//Possible values.// Prefix: '/',// Tag: [{ 'Key': 'key1', 'Value': 'value1' }, { 'Key': 'key2', 'Value': 'value2' }],//if only this, => 'DeleteMarkerReplication': { 'Status': 'Disabled' },And:{Prefix:'/',Tag:[{Key:'key1',Value:'value1'},{Key:'key2',Value:'value2'},],},},ExistingObjectReplication:{Status:'Enabled'},},],}awaits3Client.setBucketReplication('source-bucket',replicationConfig)Get replication config of a Bucket
Parameters
| Param | Type | Description |
|---|---|---|
bucketName | string | Name of the bucket. |
Example
constreplicatinConfig=awaitminioClient.getBucketReplication('source-bucket')console.log(replicatinConfig)Remove replication config of a Bucket
Parameters
| Param | Type | Description |
|---|---|---|
bucketName | string | Name of the bucket. |
Example
awaitminioClient.removeBucketReplication('source-bucket')Set Tags on a Bucket
Parameters
| Param | Type | Description |
|---|---|---|
bucketName | string | Name of the bucket. |
tags | object | Tags map Configuration e.g:{<tag-key-1>:<tag-value-1>} |
Example
awaitminioClient.setBucketTagging('bucketname',tags)Remove Tags on a Bucket
Parameters
| Param | Type | Description |
|---|---|---|
bucketName | string | Name of the bucket. |
Example
awaitminioClient.removeBucketTagging('bucketname')Gets Tags on a Bucket
Parameters
| Param | Type | Description |
|---|---|---|
bucketName | string | Name of the bucket. |
Example
consttagList=awaitminioClient.getBucketTagging('bucketname')console.log(tagList)Set Lifecycle Configuration on a Bucket
Parameters
| Param | Type | Description |
|---|---|---|
bucketName | string | Name of the bucket. |
lifecycleConfig | object | Valid Lifecycle Configuration or (null or'' ) to remove policy configuration |
Example
constlifecycleConfig={Rule:[{ID:'Transition and Expiration Rule',Status:'Enabled',Filter:{Prefix:'',},Expiration:{Days:'3650',},},],}awaitminioClient.setBucketLifecycle('bucketname',lifecycleConfig)Get Lifecycle Configuration of a Bucket
Parameters
| Param | Type | Description |
|---|---|---|
bucketName | string | Name of the bucket. |
Example
awaitminioClient.getBucketLifecycle('bucketname')Remove Lifecycle Configuration of a Bucket
Parameters
| Param | Type | Description |
|---|---|---|
bucketName | string | Name of the bucket. |
Example
awaitminioClient.removeBucketLifecycle('bucketname')Set Object lock config on a Bucket
Parameters
| Param | Type | Description |
|---|---|---|
bucketName | string | Name of the bucket. |
lockConfig | object | Lock Configuration can be either{} to reset or object with all of the following key/value pairs:{mode: ["COMPLIANCE"/'GOVERNANCE'], unit: ["Days"/"Years"], validity: <a-valid-number-for-unit>} |
Example 1
awaitminioClient.setObjectLockConfig('my-bucketname',{mode:'COMPLIANCE',unit:'Days',validity:10})Example 2To reset/remove object lock config on a bucket.
awaits3Client.setObjectLockConfig('my-bucketname',{})Get Lock config on a Bucket
Parameters
| Param | Type | Description |
|---|---|---|
bucketName | string | Name of the bucket. |
**Example **Get object lock configuration on a Bucket
awaitminioClient.getObjectLockConfig('my-bucketname')Set encryption configuration on a Bucket
Parameters
| Param | Type | Description |
|---|---|---|
bucketName | string | Name of the bucket. |
encryptionConfig | object | Encryption Configuration can be either omitted or{} or a valid and supported encryption config. by default:{Rule:[{ApplyServerSideEncryptionByDefault:{SSEAlgorithm:"AES256"}}]} is applied. |
**Example **Set Encryption configuration on a Bucket
awaits3Client.setBucketEncryption('my-bucketname')Example 1Set Encryption configuration on a Bucket with an Algorithm
awaits3Client.setBucketEncryption('my-bucketname',{Rule:[{ApplyServerSideEncryptionByDefault:{SSEAlgorithm:'AES256'}}],})Get encryption configuration of a Bucket
Parameters
| Param | Type | Description |
|---|---|---|
bucketName | string | Name of the bucket. |
**Example **Get Encryption configuration of a Bucket
awaits3Client.getBucketEncryption('my-bucketname')Remove encryption configuration of a Bucket
Parameters
| Param | Type | Description |
|---|---|---|
bucketName | string | Name of the bucket. |
**Example **Remove Encryption configuration of a Bucket
awaits3Client.removeBucketEncryption('my-bucketname')Downloads an object as a stream.
Parameters
| Param | Type | Description |
|---|---|---|
bucketName | string | Name of the bucket. |
objectName | string | Name of the object. |
getOpts | object | Options to get the object. Default is{}. (optional) |
Return Value
| Param | Type | Description |
|---|---|---|
stream | stream.Readable | Stream emitting the object content. |
Example
letsize=0constdataStream=awaitminioClient.getObject('mybucket','photo.jpg')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)})Example
Get a specific object version.
letsize=0constdataStream=awaitminioClient.getObject('mybucket','photo.jpg',{versionId:'my-versionId'})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)})Example
Get a Server Side Encrypted object.
letsize=0constdataStream=awaitminioClient.getObject('mybucket','photo.jpg',{SSECustomerAlgorithm:'AES256',SSECustomerKey:'YOUR_KEY',SSECustomerKeyMD5:'YOUR_MD5',})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)})Downloads the specified range bytes of an object as a stream.
Parameters
| Param | Type | Description |
|---|---|---|
bucketName | string | Name of the bucket. |
objectName | string | Name of the object. |
offset | number | offset of the object from where the stream will start. |
length | number | length of the object that will be read in the stream (optional, if not specified we read the rest of the file from the offset). |
getOpts | object | Options to get the object. Default is{}. (optional) |
callback(err, stream) | function | Callback is called witherr in case of error.stream is the object content stream. If no callback is passed, aPromise is returned. |
Return Value
| Param | Type | Description |
|---|---|---|
stream | Stream | Stream emitting the object content. |
Example
letsize=0// reads 30 bytes from the offset 10.constdataStream=awaitminioClient.getPartialObject('mybucket','photo.jpg',10,30)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)})ExampleTo get a specific version of an object
constversionedObjSize=0// reads 30 bytes from the offset 10.constdataStream=awaitminioClient.getPartialObject('mybucket','photo.jpg',10,30,{versionId:'my-versionId'})dataStream.on('data',function(chunk){versionedObjSize+=chunk.length})dataStream.on('end',function(){console.log('End. Total size = '+versionedObjSize)})dataStream.on('error',function(err){console.log(err)})ExampleTo get a Server Side Encrypted object.
constversionedObjSize=0// reads 30 bytes from the offset 10.constdataStream=awaitminioClient.getPartialObject('mybucket','photo.jpg',10,30,{SSECustomerAlgorithm:'AES256',SSECustomerKey:'YOUR_KEY',SSECustomerKeyMD5:'YOUR_MD5',})dataStream.on('data',function(chunk){versionedObjSize+=chunk.length})dataStream.on('end',function(){console.log('End. Total size = '+versionedObjSize)})dataStream.on('error',function(err){console.log(err)})Downloads and saves the object as a file in the local filesystem.
Parameters
| Param | Type | Description |
|---|---|---|
bucketName | string | Name of the bucket. |
objectName | string | Name of the object. |
filePath | string | Path on the local filesystem to which the object data will be written. |
getOpts | object | Options to get the object. Default is{}. (optional) |
callback(err) | function | Callback is called witherr in case of error. If no callback is passed, aPromise is returned. |
Return Value
| Value | Type | Description |
|---|---|---|
err | object | Error in case of any failures |
file | file | Streamed Output file at the specifiedfilePath |
Example
minioClient.fGetObject('mybucket','photo.jpg','/tmp/photo.jpg',function(err){if(err){returnconsole.log(err)}console.log('success')})ExampleTo Stream a specific object version into a file.
minioClient.fGetObject(bucketName,objNameValue,'./download/MyImage.jpg',{versionId:'my-versionId'},function(e){if(e){returnconsole.log(e)}console.log('success')})ExampleTo Stream a Server Side Encrypted object into a file.
minioClient.fGetObject(bucketName,objNameValue,'./download/MyImage.jpg',{SSECustomerAlgorithm:'AES256',SSECustomerKey:'YOUR_KEY',SSECustomerKeyMD5:'YOUR_MD5',},function(e){if(e){returnconsole.log(e)}console.log('success')},)Uploads an object from a stream/Buffer.
Parameters
| Param | Type | Description |
|---|---|---|
bucketName | string | Name of the bucket. |
objectName | string | Name of the object. |
stream | Stream | Readable stream. |
size | number | Size of the object (optional). |
metaData | Javascript Object | metaData of the object (optional). |
callback(err, objInfo) | function | Non-nullerr indicates error, in case of Success,objInfo containsetagstring andversionIdstring of the object. If no callback is passed, aPromise is returned. |
Return Value
| Value | Type | Description |
|---|---|---|
err | object | Error in case of any failures |
objInfo.etag | string | etag of an object |
objInfo.versionId | string | versionId of an object (optional) |
Example
The maximum size of a single object is limited to 5TB. putObject transparently uploads objects larger than 64MiB in multiple parts. Uploaded data is carefully verified using MD5SUM signatures.
import*asFsfrom'fs'constfile='/tmp/40mbfile'constfileStream=Fs.createReadStream(file)constfileStat=Fs.stat(file,function(err,stats){if(err){returnconsole.log(err)}minioClient.putObject('mybucket','40mbfile',fileStream,stats.size,function(err,objInfo){if(err){returnconsole.log(err)// err should be null}console.log('Success',objInfo)})})Parameters
| Param | Type | Description |
|---|---|---|
bucketName | string | Name of the bucket. |
objectName | string | Name of the object. |
string or Buffer | Stream orBuffer | Readable stream. |
metaData | Javascript Object | metaData of the object (optional). |
callback(err, etag) | function | Non-nullerr indicates error,etagstring is the etag of the object uploaded. |
Example
constbuffer='Hello World'minioClient.putObject('mybucket','hello-file',buffer,function(err,etag){returnconsole.log(err,etag)// err should be null})Uploads contents from a file to objectName.
Parameters
| Param | Type | Description |
|---|---|---|
bucketName | string | Name of the bucket. |
objectName | string | Name of the object. |
filePath | string | Path of the file to be uploaded. |
metaData | Javascript Object | Metadata of the object. |
callback(err, objInfo)function: non nullerr indicates error,objInfoobject is the information about the object uploaded which containsversionId string andetag string. |
Return Value
| Value | Type | Description |
|---|---|---|
err | object | Error in case of any failures |
objInfo.etag | string | etag of an object |
objInfo.versionId | string | versionId of an object (optional) |
Example
The maximum size of a single object is limited to 5TB. fPutObject transparently uploads objects larger than 64MiB in multiple parts. Uploaded data is carefully verified using MD5SUM signatures.
constfile='/tmp/40mbfile'constmetaData={'Content-Type':'text/html','Content-Language':123,'X-Amz-Meta-Testing':1234,example:5678,}minioClient.fPutObject('mybucket','40mbfile',file,metaData,function(err,objInfo){if(err){returnconsole.log(err)}console.log('Success',objInfo.etag,objInfo.versionId)})Copy a source object into a new object in the specified bucket.
Parameters
| Param | Type | Description |
|---|---|---|
targetBucketName | string | Name of the bucket. |
targetObjectName | string | Name of the object. |
sourceBucketNameAndObjectName | string | Path of the file to be copied. |
conditions | CopyConditions | Conditions to be satisfied before allowing object copy. |
Example
constconds=newMinio.CopyConditions()conds.setMatchETag('bd891862ea3e22c93ed53a098218791d')awaitminioClient.copyObject('mybucket','newobject','/mybucket/srcobject',conds)Gets metadata of an object.
Parameters
| Param | Type | Description |
|---|---|---|
bucketName | string | Name of the bucket. |
objectName | string | Name of the object. |
statOpts | object | Version of the object in the form{versionId:"my-versionId"}. Default is{}. (optional) |
callback(err, stat) | function | err is notnull in case of error,stat contains the object information listed below. If no callback is passed, aPromise is returned. |
Return Value
| Param | Type | Description |
|---|---|---|
stat.size | number | size of the object. |
stat.etag | string | etag of the object. |
stat.versionId | string | version of the object. |
stat.metaData | Javascript Object | metadata of the object. |
stat.lastModified | Date | Last Modified time stamp. |
Example
conststat=awaitminioClient.statObject('mybucket','photo.jpg')console.log(stat)Example stat on a version of an object
conststat=awaitminioClient.statObject('mybucket','photo.jpg',{versionId:'my-versionId'})console.log(stat)Removes an object.
Parameters
| Param | Type | Description |
|---|---|---|
bucketName | string | Name of the bucket. |
objectName | string | Name of the object. |
removeOpts | object | Version of the object in the form{versionId:"my-versionId", governanceBypass: true or false }. Default is{}. (Optional) |
Example 1
;(asyncfunction(){awaitminioClient.removeObject('mybucket','photo.jpg')console.log('Removed the object')})()Example 2Delete a specific version of an object
;(asyncfunction(){try{awaitminioClient.removeObject('mybucket','photo.jpg',{versionId:'my-versionId'})console.log('Removed the object')}catch(err){console.log('Unable to remove object',err)}})()Example 3Remove an object version locked with retention modeGOVERNANCE using thegovernanceBypass remove option
;(asyncfunction(){awaits3Client.removeObject('my-bucketname','my-objectname',{versionId:'my-versionId',governanceBypass:true})console.log('Success')})()Remove all objects in the objectsList.
Parameters
| Param | Type | Description |
|---|---|---|
bucketName | string | Name of the bucket. |
objectsList | object | list of objects in the bucket to be removed. any one of the formats: 1. List of Object names as array of strings which are object keys:['objectname1','objectname2'] 2. List of Object name and VersionId as an object: [{name:“my-obj-name”,versionId:“my-versionId”}] |
Example
constobjectsList=[]// List all object paths in bucket my-bucketname.constobjectsStream=s3Client.listObjects('my-bucketname','my-prefixname',true)objectsStream.on('data',function(obj){objectsList.push(obj.name)})objectsStream.on('error',function(e){console.log(e)})objectsStream.on('end',async()=>{awaits3Client.removeObjects(bucket,objectsList)})Example1
With versioning Support
constobjectsList=[]constbucket='my-bucket'constprefix='my-prefix'constrecursive=falseconstobjectsStream=s3Client.listObjects(bucket,prefix,recursive,{IncludeVersion:true})objectsStream.on('data',function(obj){objectsList.push(obj)})objectsStream.on('error',function(e){returnconsole.log(e)})objectsStream.on('end',async()=>{awaits3Client.removeObjects(bucket,objectsList)})Removes a partially uploaded object.
Parameters
| Param | Type | Description |
|---|---|---|
bucketName | string | Name of the bucket. |
objectName | string | Name of the object. |
Example
awaitminioClient.removeIncompleteUpload('mybucket','photo.jpg')Apply retention on an object.
Parameters
| Param | Type | Description |
|---|---|---|
bucketName | string | Name of the bucket. |
objectName | string | Name of the object. |
retentionOpts | object | Options for retention like :{ governanceBypass:true/false ,mode:COMPLIANCE/GOVERNANCE, retainUntilDate: _date_ , versionId:"my-versionId" } Default is{} (Optional) |
ExampleApply object retention on an object
constbucketName='my-bucket'constobjectName='my-object'constexpirationDate=newDate()expirationDate.setDate(expirationDate.getDate()+1)expirationDate.setUTCHours(0,0,0,0)//Should be start of the day.(midnight)constversionId='e67b4b08-144d-4fc4-ba15-43c3f7f9ba74'awaitminioClient.putObjectRetention(bucketName,objectName,{Mode:'GOVERNANCE',retainUntilDate:retainUntilDate.toISOString(),versionId:versionId,})Get retention config of an object
Parameters
| Param | Type | Description |
|---|---|---|
bucketName | string | Name of the bucket. |
objectName | string | Name of the object. |
getOpts | object | Options for retention like :{ versionId:"my-versionId" } Default is{} (Optional) |
Example 1
constretentionInfo=awaitminioClient.getObjectRetention('bucketname','objectname')console.log(retentionInfo)Example 2
constretInfoForVersionId=awaitminioClient.getObjectRetention('bucketname','objectname',{versionId:'my-versionId',})console.log(retInfoForVersionId)Put Tags on an Object
Parameters
| Param | Type | Description |
|---|---|---|
bucketName | string | Name of the bucket. |
objectName | string | Name of the object. |
tags | object | Tags map Configuration e.g:{<tag-key-1>:<tag-value-1>} |
putOpts | object | Default is {}. e.g{versionId:"my-version-id"}. (Optional) |
Example
awaitminioClient.setObjectTagging('bucketname','object-name',tags)Example 1Put tags on a version of an object.
awaitminioClient.setObjectTagging('bucketname','object-name',tags,{versionId:'my-version-id'})Remove Tags on an Object
Parameters
| Param | Type | Description |
|---|---|---|
bucketName | string | Name of the bucket. |
objectName | string | Name of the object. |
removeOpts | object | Defaults to {}. e.g{versionId:"my-version-id"}. (Optional) |
Example
awaitminioClient.removeObjectTagging('bucketname','object-name')Example1Remove tags on a version of an object.
awaitminioClient.removeObjectTagging('bucketname','object-name',{versionId:'my-object-version-id'})Get Tags of an Object
Parameters
| Param | Type | Description |
|---|---|---|
bucketName | string | Name of the bucket. |
objectName | string | Name of the object. |
getOpts | object | Defaults to {}. e.g{versionId:"my-version-id"}. (Optional) |
Example
console.log(awaitminioClient.getObjectTagging('bucketname','object-name'))Example1Get tags on a version of an object.
console.log(awaitminioClient.getObjectTagging('bucketname','object-name',{versionId:'my-object-version-id'}))Get legal hold on an object.
Parameters
| Param | Type | Description |
|---|---|---|
bucketName | string | Name of the bucket. |
objectName | string | Name of the object. |
getOpts | object | Legal hold configuration options. e.g{versionId:'my-version-uuid'}. Defaults to{} . |
Example 1
Get Legal hold of an object.
constlegalholdStatus=awaitminioClient.getObjectLegalHold('bucketName','objectName')Example 2
Get Legal hold of an object with versionId.
constlegalholdStatus=awaitminioClient.getObjectLegalHold('bucketName','objectName',{versionId:'my-obj-version-uuid',})Set legal hold on an object.
Parameters
| Param | Type | Description |
|---|---|---|
bucketName | string | Name of the bucket. |
objectName | string | Name of the object. |
setOpts | object | Legal hold configuration options to set. e.g{versionId:'my-version-uuid', status:'ON or OFF'}. Defaults to{status:'ON'} if not passed. |
Example 1
Set Legal hold of an object.
constlegalholdStatus=awaitminioClient.setObjectLegalHold('bucketName','objectName',{Status:'ON'})Example 2
Set Legal hold of an object with versionId.
constlegalholdStatus=awaitminioClient.setObjectLegalHold('bucketName','objectName',{Status:'ON',versionId:'my-obj-version-uuid',})Compose an object from parts
Parameters
| Param | Type | Description |
|---|---|---|
destObjConfig | object | Destination Object configuration of the typeCopyDestinationOptions |
sourceObjectList | object[] | Array of object(parts) source to compose into an object. Each part configuration should be of typeCopySourceOptions |
Example 1
Compose an Object from its parts .
import*asminiofrom'minio'constsourceList=[newminio.CopySourceOptions({Bucket:'source-bucket',Object:'parta',}),newminio.CopySourceOptions({Bucket:'source-bucket',Object:'partb',}),newminio.CopySourceOptions({Bucket:'source-bucket',Object:'partc',}),newminio.CopySourceOptions({Bucket:'source-bucket',Object:'partd',}),]constdestOption=newminio.CopyDestinationOptions({Bucket:'dest-bucket',Object:'100MB.zip',})//using Promise style.awaitminioClient.composeObject(destOption,sourceList)Select contents of an object (S3 Select).
Parameters
| Param | Type | Description |
|---|---|---|
bucketName | string | Name of the bucket. |
objectName | string | Name of the object. |
selectOpts | object |
Example 1Select all values
constselectOpts={expression:'SELECT * FROM s3object s where s."Name" = \'Jane\'',expressionType:'SQL',inputSerialization:{CSV:{FileHeaderInfo:'Use',RecordDelimiter:'\n',FieldDelimiter:','},CompressionType:'NONE',},outputSerialization:{CSV:{RecordDelimiter:'\n',FieldDelimiter:','}},requestProgress:{Enabled:true},}constres=awaitminioClient.selectObjectContent('bucketName','objectName',selectOpts)console.log(res)Presigned URLs are generated for temporary download/upload access to private objects.
Generates a presigned URL for the provided HTTP method, ‘httpMethod’. Browsers/Mobile clients may point to this URL to directly download objects even if the bucket is private. This presigned URL can have an associated expiration time in seconds after which the URL is no longer valid. The default value is 7 days.
Parameters
| Param | Type | Description |
|---|---|---|
bucketName | string | Name of the bucket. |
objectName | string | Name of the object. |
expiry | number | Expiry time in seconds. Default value is 7 days. (optional) |
reqParams | object | request parameters. (optional) e.g {versionId:“10fa9946-3f64-4137-a58f-888065c0732e”} |
requestDate | Date | A date object, the url will be issued at. Default value is now. (optional) |
Example1
// presigned url for 'getObject' method.// expires in a day.constpresignedUrl=awaitminioClient.presignedUrl('GET','mybucket','hello.txt',24*60*60)console.log(presignedUrl)Example2
// presigned url for 'listObject' method.// Lists objects in 'myBucket' with prefix 'data'.// Lists max 1000 of them.awaitminioClient.presignedUrl('GET','mybucket','',1000,{prefix:'data','max-keys':1000})Example 3
// Get Object with versionidawaitminioClient.presignedUrl('GET','mybucket','',1000,{versionId:'10fa9946-3f64-4137-a58f-888065c0732e'})Generates a presigned URL for HTTP GET operations. Browsers/Mobile clients may point to this URL to directly download objects even if the bucket is private. This presigned URL can have an associated expiration time in seconds after which the URL is no longer valid. The default value is 7 days.
Parameters
| Param | Type | Description |
|---|---|---|
bucketName | string | Name of the bucket. |
objectName | string | Name of the object. |
expiry | number | Expiry time in seconds. Default value is 7 days. (optional) |
respHeaders | object | response headers to override (optional) |
requestDate | Date | A date object, the url will be issued at. Default value is now. (optional) |
Example
// expires in a day.constpresignedUrl=awaitminioClient.presignedGetObject('mybucket','hello.txt',24*60*60)console.log(presignedUrl)Generates a presigned URL for HTTP PUT operations. Browsers/Mobile clients may point to this URL to upload objects directly to a bucket even if it is private. This presigned URL can have an associated expiration time in seconds after which the URL is no longer valid. The default value is 7 days.
Parameters
| Param | Type | Description |
|---|---|---|
bucketName | string | Name of the bucket. |
objectName | string | Name of the object. |
expiry | number | Expiry time in seconds. Default value is 7 days. |
Example
// expires in a day.constpresignedUrl=awaitminioClient.presignedPutObject('mybucket','hello.txt',24*60*60)console.log(presignedUrl)Allows setting policy conditions to a presigned URL for POST operations. Policies such as bucket name to receive object uploads, key name prefixes, expiry policy may be set.
Parameters
| Param | Type | Description |
|---|---|---|
policy | object | Policy object created by minioClient.newPostPolicy() |
Create policy:
constpolicy=minioClient.newPostPolicy()Apply upload policy restrictions:
// Policy restricted only for bucket 'mybucket'.policy.setBucket('mybucket')// Policy restricted only for hello.txt object.policy.setKey('hello.txt')or
// Policy restricted for incoming objects with keyPrefix.policy.setKeyStartsWith('keyPrefix')constexpires=newDate()expires.setSeconds(24*60*60*10)// Policy expires in 10 days.policy.setExpires(expires)// Only allow 'text'.policy.setContentType('text/plain')// Set content disposition response header.policy.setContentDisposition('attachment; filename=text.txt')// Only allow content size in range 1KB to 1MB.policy.setContentLengthRange(1024,1024*1024)// Set key-value user defined metadatapolicy.setUserMetaData({key:'value',})POST your content from the browser usingsuperagent:
const{postURL,formData}=awaitminioClient.presignedPostPolicy(policy)constreq=superagent.post(postURL)_.each(formData,function(value,key){req.field(key,value)})// file contents.req.attach('file','/path/to/hello.txt','hello.txt')req.end(function(err,res){if(err){returnconsole.log(err.toString())}console.log('Upload successful.')})Buckets are configured to trigger notifications on specified types of events and paths filters.
Fetch the notification configuration stored in the S3 provider and that belongs to the specified bucket name.
Parameters
| Param | Type | Description |
|---|---|---|
bucketName | string | Name of the bucket. |
callback(err, bucketNotificationConfig) | function | Callback function is called with nonnull err value in case of error.bucketNotificationConfig will be the object that carries all notification configurations associated to bucketName. If no callback is passed, aPromise is returned. |
Example
minioClient.getBucketNotification('mybucket',function(err,bucketNotificationConfig){if(err)returnconsole.log(err)console.log(bucketNotificationConfig)})Upload a user-created notification configuration and associate it to the specified bucket name.
Parameters
| Param | Type | Description |
|---|---|---|
bucketName | string | Name of the bucket. |
bucketNotificationConfig | BucketNotification | Javascript object that carries the notification configuration. |
callback(err) | function | Callback function is called with nonnull err value in case of error. If no callback is passed, aPromise is returned. |
Example
// Create a new notification objectconstbucketNotification=newMinio.NotificationConfig()// Setup a new Queue configurationconstarn=Minio.buildARN('aws','sqs','us-west-2','1','webhook')constqueue=newMinio.QueueConfig(arn)queue.addFilterSuffix('.jpg')queue.addFilterPrefix('myphotos/')queue.addEvent(Minio.ObjectReducedRedundancyLostObject)queue.addEvent(Minio.ObjectCreatedAll)// Add the queue to the overall notification objectbucketNotification.add(queue)minioClient.setBucketNotification('mybucket',bucketNotification,function(err){if(err)returnconsole.log(err)console.log('Success')})Remove the bucket notification configuration associated to the specified bucket.
Parameters
| Param | Type | Description |
|---|---|---|
bucketName | string | Name of the bucket |
callback(err) | function | Callback function is called with nonnull err value in case of error. If no callback is passed, aPromise is returned. |
minioClient.removeAllBucketNotification('my-bucketname',function(e){if(e){returnconsole.log(e)}console.log('True')})Listen for notifications on a bucket. Additionally one can providerfilters for prefix, suffix and events. There is no prior set bucket notificationneeded to use this API. This is an MinIO extension API where unique identifiersare registered and unregistered by the server automatically based on incoming requests.
Returns anEventEmitter, which will emit anotification event carrying the record.
To stop listening, call.stop() on the returnedEventEmitter.
Parameters
| Param | Type | Description |
|---|---|---|
bucketName | string | Name of the bucket |
prefix | string | Object key prefix to filter notifications for. |
suffix | string | Object key suffix to filter notifications for. |
events | Array | Enables notifications for specific event types. |
Seehere for a full example.
constlistener=minioClient.listenBucketNotification('my-bucketname','photos/','.jpg',['s3:ObjectCreated:*'])listener.on('notification',function(record){// For example: 's3:ObjectCreated:Put event occurred (2016-08-23T18:26:07.214Z)'console.log('%s event occurred (%s)',record.eventName,record.eventTime)listener.stop()})Get the bucket policy associated with the specified bucket. IfobjectPrefixis not empty, the bucket policy will be filtered based on object permissionsas well.
Parameters
| Param | Type | Description |
|---|---|---|
bucketName | string | Name of the bucket |
// Retrieve bucket policy of 'my-bucketname'constpolicy=awaitminioClient.getBucketPolicy('my-bucketname')console.log(`Bucket policy file:${policy}`)Set the bucket policy on the specified bucket.bucketPolicy is detailed here.
Parameters
| Param | Type | Description |
|---|---|---|
bucketName | string | Name of the bucket. |
bucketPolicy | string | bucket policy. |
// Set the bucket policy of `my-bucketname`awaitminioClient.setBucketPolicy('my-bucketname',JSON.stringify(policy))Set AWS S3 transfer acceleration endpoint for all API requests hereafter.NOTE: This API applies only to AWS S3 and is a no operation for S3 compatible object storage services.
Parameters
| Param | Type | Description |
|---|---|---|
endpoint | string | Set to new S3 transfer acceleration endpoint. |
Set the HTTP/HTTPS request options. Supported options areagent (http.Agent()),family (IP address family to use while resolvinghost orhostname), and tls related options (‘agent’, ‘ca’, ‘cert’, ‘ciphers’, ‘clientCertEngine’, ‘crl’, ‘dhparam’, ’ecdhCurve’, ‘honorCipherOrder’, ‘key’, ‘passphrase’, ‘pfx’, ‘rejectUnauthorized’, ‘secureOptions’, ‘secureProtocol’, ‘servername’, ‘sessionIdContext’) documentedhere
// Do not reject self signed certificates.minioClient.setRequestOptions({rejectUnauthorized:false})