var Minio = require('minio')
const fs = require('fs');
// Instantiate the minio client with the endpoint
// and access keys as shown below.
var minioClient = new Minio.Client({
endPoint: 't1', //这里不能带http或者https
port: 9000,
useSSL: false, //不需要https
accessKey: 'admin', //账号密码同web登陆时一致
secretKey: 'admin123'
});
// File that needs to be uploaded.
var file = 'e:\\file\\m1.jpg'
// Make a bucket called europetrip.
// 上传文件
fs.readFile(file, (err, data) => {
if (err) throw err;
const metaData = {
'Content-Type': 'image/jpeg' // 设置 Content-Type
};
const objectName = 'example.jpg';
minioClient.putObject('btest2', objectName, data, metaData, (err, etag) => {
if (err) throw err;
console.log(`Successfully uploaded ${objectName}.`);
});
});
node.js上传图片到minio
于 2023-04-09 10:49:36 首次发布