minio上传图片设置文件类型
时间: 2023-08-06 17:03:38 浏览: 1129
要设置Minio上传图片的文件类型,可以使用Minio的`putObject`方法并在请求头中设置`Content-Type`属性为对应的MIME类型。
以下是一个示例代码,使用Node.js和minio-js库上传图片并设置文件类型为image/jpeg:
```javascript
const Minio = require('minio');
const minioClient = new Minio.Client({
endPoint: 'minio.example.com',
port: 9000,
useSSL: true,
accessKey: 'YOUR_ACCESS_KEY',
secretKey: 'YOUR_SECRET_KEY'
});
const bucketName = 'your-bucket-name';
const objectName = 'your-object-name.jpg';
const filePath = '/path/to/your/image.jpg';
const contentType = 'image/jpeg'; // 设置文件类型为image/jpeg
const metaData = {
'Content-Type': contentType
};
minioClient.fPutObject(bucketName, objectName, filePath, metaData, (err, etag) => {
if (err) {
console.log(err);
return;
}
console.log('File uploaded successfully');
});
```
请将`YOUR_ACCESS_KEY`,`YOUR_SECRET_KEY`,`your-bucket-name`,`your-object-name.jpg`和`/path/to/your/image.jpg`替换为你自己的实际值。