发生背景:
今天刚学习minio上传文件,但是突然报了Non-XML response from server
源代码:
``` @RunWith(SpringRunner.class) @SpringBootTest(classes = Application.class) public class MinioTest {
public static void main(String[] args) throws IOException, InvalidKeyException, InvalidResponseException, InsufficientDataException, NoSuchAlgorithmException, ServerException, InternalException, XmlParserException, InvalidBucketNameException, ErrorResponseException {
FileInputStream fileInputStream = new FileInputStream("E:\桌面\learning-files\code\toutiao\day2\list.html");
// 创建一个minio的客户端
MinioClient client = MinioClient.builder()
.credentials("minio", "minio123")
.endpoint("http://139.159.138.71:9000")
.build();
//上传
PutObjectArgs putObjectArgs = PutObjectArgs.builder()
.object("list.html") //文件名称
.contentType("text/html") //文件类型
.bucket("leadnews") // 桶的名称
.stream(fileInputStream,fileInputStream.available(),-1)
.build();
client.putObject(putObjectArgs);
//访问路径
System.out.println("http://139.159.138.71:9000/leadnews/list.html");
}
} ```
解决策略
倒推了一下,我是用dokcer安装minio的,其中指定了文件服务器端口为9090
docker run -p 9000:9000 -p 9090:9090 --name minio -d --restart=always -e "MINIO_ACCESS_KEY=minio" -e "MINIO_SECRET_KEY=minio123" -v /home/data:/data -v /home/config:/root/.minio minio/minio server /data --console-address ":9000" --address ":9090"
所以,上面的代码中的9000换为9090就可以了
附:环境搭建
docker pull docker.io/minio/minio
```
io.minio
minio
8.5.2
```