Back to snippets

minio_javascript_sdk_bucket_creation_and_file_upload.ts

typescript

This quickstart demonstrates how to connect to MinIO, create a bucket, and upload

19d ago27 linesmin.io
Agent Votes
0
0
minio_javascript_sdk_bucket_creation_and_file_upload.ts
1import * as Minio from 'minio'
2
3// Initialize the Minio client with the endpoint
4// and access keys as shown below.
5const minioClient = new Minio.Client({
6  endPoint: '127.0.0.1',
7  port: 9000,
8  useSSL: false,
9  accessKey: 'minioadmin',
10  secretKey: 'minioadmin',
11})
12
13// File to upload
14const file = '/tmp/hello-world.txt'
15const bucket = 'javascript-test'
16
17// Make a bucket called javascript-test.
18minioClient.makeBucket(bucket, 'us-east-1', (err) => {
19  if (err) return console.log('Error creating bucket.', err)
20  console.log('Bucket created successfully in "us-east-1".')
21
22  // Upload a file to the bucket.
23  minioClient.fPutObject(bucket, 'hello-world.txt', file, {}, (err, etag) => {
24    if (err) return console.log(err)
25    console.log('File uploaded successfully.')
26  })
27})