使用restsharp上传minio后文件无法预览

通过观察minio内部的文件发现文件Content-Type显示异常,
显示内容为 multipart/form-data; boundary="8184e3be-33df-4d78-a2ea-571693850fe4"

通过直接在minio提供的web页面上传后对比发现,正常情况下显示的类型应该为 application/pdf

随后使用postman手动提交,通过设置提交方式为binary (二进制) 上传后显示的类型正确,文件预览也能正常显示

随后根据c-sharp-restsharp-put-method-and-send-raw-bytes-protobuf
得知restsharp导致的这个问题,所以直接使用HttpClient上传并设置Content-Type为文件的实际类型即可

var filePath="";  //需要上传的文件路径
byte[] fileBytes = File.ReadAllBytes(filePath);
var client = new HttpClient();
var httpContent = new ByteArrayContent(fileBytes);
//httpContent.Headers.Add("Content-Type", "application/pdf");
httpContent.Headers.Add("Content-Type", contentType);
client.PutAsync(uploadInfo.UploadUrl, httpContent);
posted @ 2024-07-08 15:33  Hey,Coder!  阅读(20)  评论(0编辑  收藏  举报