· 9 years ago · Jan 07, 2017, 06:18 AM
1var Minio = require('minio')
2
3// Instantiate the minio client with the endpoint
4// and access keys as shown below.
5var minioClient = new Minio.Client({
6 endPoint: 'play.minio.io',
7 port: 9000,
8 secure: true,
9 accessKey: 'Q3AM3UQ867SPQQA43P2F',
10 secretKey: 'zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG'
11});
12
13// Start listening for notifications on the bucket, using our arn.
14var poller = minioClient.listenBucketNotification('atuljha', 'img-', '.jpg', ['s3:ObjectCreated:*'])
15// Notification will be emitted every time a new notification is received.
16// For object creation, here is a sample record:
17
18// { eventVersion: '2.0',
19// eventSource: 'aws:s3',
20// awsRegion: 'us-east-1',
21// eventTime: '2016-08-23T18:26:07.214Z',
22// eventName: 's3:ObjectCreated:Put',
23// userIdentity: { principalId: 'minio' },
24// requestParameters: { sourceIPAddress: '...' },
25// responseElements: {},
26// s3:
27// { s3SchemaVersion: '1.0',
28// configurationId: 'Config',
29// bucket:
30// { name: 'bucket1',
31// ownerIdentity: [Object],
32// arn: 'arn:aws:s3:::bucket1' },
33// object: { key: 'photos%2Fobject.jpg', size: 10, sequencer: '...' } } }
34poller.on('notification', record => {
35 console.log('New object: %s/%s (size: %d)', record.s3.bucket.name,
36 record.s3.object.key, record.s3.object.size)
37
38 // Now that we've received our notification, we can cancel the listener.
39 // We could leave it open if we wanted to continue to receive notifications.
40 poller.stop()
41})