nodejs測試上傳文件到minio分佈式對象存儲服務器

首先需要安裝minio的客戶端js

npm install --save minio

安裝minio支持typeScript 語法格式

npm install --save-dev @types/minio

編程上傳文件測試代碼file-uploader.js內容如下

var Minio = require('minio')
// Instantiate the minio client with the endpoint
// and access keys as shown below.
var minioClient = new Minio.Client({
    endPoint: '192.168.142.115', //這裏不能帶http或者https
    port: 9000,
    useSSL: false, //不需要https
    accessKey: 'minioadmin', //賬號密碼同web登陸時一致
    secretKey: 'minioadmin'
});
// File that needs to be uploaded.
var file = 'D:\\photos-europe.tar'
// Make a bucket called europetrip.
minioClient.makeBucket('europetrip', 'us-east-1', function(err) {
    if (err) return console.log(err)
    console.log('Bucket created successfully in "us-east-1".')
    var metaData = {
        'Content-Type': 'application/octet-stream',
        'X-Amz-Meta-Testing': 1234,
        'example': 5678
    }
    // Using fPutObject API upload your file to the bucket europetrip.
    minioClient.fPutObject('europetrip', 'photos-europe.tar', file, metaData, function(err, etag) {
      if (err) return console.log(err)
      console.log('File uploaded successfully.')
    });
});

運行測試代碼

node file-uploader.js
Bucket created successfully in "us-east-1".

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章