Skip to content

Commit 585b4ae

Browse files
committed
文件中文名称进行url编码
1 parent caa111f commit 585b4ae

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

WebApiClient/Parameterables/MulitpartFile.cs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Diagnostics;
33
using System.IO;
4+
using System.Text;
45
using System.Threading.Tasks;
56
using WebApiClient.Contexts;
67

@@ -13,19 +14,34 @@ namespace WebApiClient.Parameterables
1314
public class MulitpartFile : IApiParameterable
1415
{
1516
/// <summary>
16-
///
17+
/// 数据流
1718
/// </summary>
1819
private readonly Stream stream;
1920

2021
/// <summary>
21-
/// 文件路径
22+
/// 本机文件路径
2223
/// </summary>
2324
private readonly string filePath;
2425

2526
/// <summary>
26-
/// 文件名
27+
/// 文件好友名称
2728
/// </summary>
28-
public string FileName { get; private set; }
29+
private readonly string fileName;
30+
31+
/// <summary>
32+
/// 获取文件好友名称
33+
/// </summary>
34+
public string FileName
35+
{
36+
get
37+
{
38+
if (string.IsNullOrEmpty(this.fileName))
39+
{
40+
return this.fileName;
41+
}
42+
return HttpUtility.UrlEncode(this.fileName, Encoding.UTF8);
43+
}
44+
}
2945

3046
/// <summary>
3147
/// 获取或设置文件的Mime
@@ -52,7 +68,7 @@ public MulitpartFile(byte[] buffer, string fileName) :
5268
public MulitpartFile(Stream stream, string fileName)
5369
{
5470
this.stream = stream ?? throw new ArgumentNullException(nameof(stream));
55-
this.FileName = fileName;
71+
this.fileName = fileName;
5672
}
5773

5874
/// <summary>
@@ -74,7 +90,7 @@ public MulitpartFile(string localFilePath)
7490
}
7591

7692
this.filePath = localFilePath;
77-
this.FileName = Path.GetFileName(localFilePath);
93+
this.fileName = Path.GetFileName(localFilePath);
7894
}
7995

8096
/// <summary>

0 commit comments

Comments
 (0)