使用.Net MinIO SDK 踩的坑

1、连接客户端时报错:MinIO API responded with message=No path allowed in endpoint 

1
2
3
4
MinioClient minioClient = new MinioClient("http://XXXX:9000",
                                          accessKey:"Q3AM3UQ867SPQQA43P2F",
                                          secretKey:"zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG"
                                          ).WithSSL();

  

解决方法:把url的前缀http://去掉即可

2、报错MinIO API responded with message=Connection error: The SSL connection could not be established, see inner exception. The handshake failed due to an unexpected packet format.. Status code=0, response=The SSL connection could not be established, see inner exception. The handshake failed due to an unexpected packet format., content=)'

没有搭https的话,把连接语句的 WithSSL() 去掉即可

3、有个需求是从FTP服务里下载文件然后上传到MInIO,FTP使用了FluentFTP SDK,下载文件时直接new一个MempryStream来存储ftp文件的流,这样会导致上传到Minio的时候获取不到真正的文件size。

1
2
3
4
var stream = new MemoryStream()
await ftpClient.DownloadAsync(stream, item.FullName);
 
await minioClient.PutObjectAsync("detection", item.Name, stream, stream.Length, "image/jpeg");

所以只能先获取字节数据,再转换成流,我也搞不懂为什么,基础知识太差了。。有大神知道的话麻烦回复一下

1
2
3
4
5
var byts= await ftpClient.DownloadAsync(item.FullName,0)
using (MemoryStream br = new MemoryStream(byts))//初始化MemoryStream,并将Buffer指向FileStream的读取结果数组
{
   await minioClient.PutObjectAsync("detection", item.Name, br, br.Length, "image/jpeg");
}

 

之后成功上传到Minio

原文地址:https://www.cnblogs.com/chinasoft/p/15304497.html