@@ -20,9 +20,9 @@ namespace RestSharp;
20
20
[ PublicAPI ]
21
21
public record FileParameter {
22
22
/// <summary>
23
- /// Provides raw data for file
23
+ /// Name of the parameter
24
24
/// </summary>
25
- public Func < Stream > GetFile { get ; }
25
+ public string Name { get ; }
26
26
27
27
/// <summary>
28
28
/// Name of the file to use when uploading
@@ -35,15 +35,18 @@ public record FileParameter {
35
35
public string ? ContentType { get ; }
36
36
37
37
/// <summary>
38
- /// Name of the parameter
38
+ /// Provides raw data for file
39
39
/// </summary>
40
- public string Name { get ; }
40
+ public Func < Stream > GetFile { get ; }
41
+
42
+ public FileParameterOptions Options { get ; }
41
43
42
- FileParameter ( string name , string fileName , Func < Stream > getFile , string ? contentType = null ) {
43
- Name = name ;
44
- FileName = fileName ;
45
- GetFile = getFile ;
46
- ContentType = contentType ?? Serializers . ContentType . Binary ;
44
+ FileParameter ( string name , string fileName , Func < Stream > getFile , string ? contentType , FileParameterOptions options ) {
45
+ Name = name ;
46
+ FileName = fileName ;
47
+ GetFile = getFile ;
48
+ Options = options ;
49
+ ContentType = contentType ?? Serializers . ContentType . Binary ;
47
50
}
48
51
49
52
/// <summary>
@@ -53,9 +56,10 @@ public record FileParameter {
53
56
/// <param name="data">The data to use as the file's contents.</param>
54
57
/// <param name="filename">The filename to use in the request.</param>
55
58
/// <param name="contentType">The content type to use in the request.</param>
59
+ /// <param name="options">File parameter options</param>
56
60
/// <returns>The <see cref="FileParameter" /></returns>
57
- public static FileParameter Create ( string name , byte [ ] data , string filename , string ? contentType = null ) {
58
- return new FileParameter ( name , filename , GetFile , contentType ) ;
61
+ public static FileParameter Create ( string name , byte [ ] data , string filename , string ? contentType = null , FileParameterOptions ? options = null ) {
62
+ return new FileParameter ( name , filename , GetFile , contentType , options ?? new FileParameterOptions ( ) ) ;
59
63
60
64
Stream GetFile ( ) {
61
65
var stream = new MemoryStream ( ) ;
@@ -73,24 +77,31 @@ Stream GetFile() {
73
77
/// <param name="getFile">Delegate that will be called with the request stream so you can write to it..</param>
74
78
/// <param name="fileName">The filename to use in the request.</param>
75
79
/// <param name="contentType">Optional: parameter content type, default is "application/g-zip"</param>
80
+ /// <param name="options">File parameter options</param>
76
81
/// <returns>The <see cref="FileParameter" /> using the default content type.</returns>
77
82
public static FileParameter Create (
78
- string name ,
79
- Func < Stream > getFile ,
80
- string fileName ,
81
- string ? contentType = null
83
+ string name ,
84
+ Func < Stream > getFile ,
85
+ string fileName ,
86
+ string ? contentType = null ,
87
+ FileParameterOptions ? options = null
82
88
)
83
- => new ( name , fileName , getFile , contentType ?? Serializers . ContentType . Binary ) ;
89
+ => new ( name , fileName , getFile , contentType ?? Serializers . ContentType . Binary , options ?? new FileParameterOptions ( ) ) ;
84
90
85
- public static FileParameter FromFile ( string fullPath , string ? name = null , string ? contentType = null ) {
86
- if ( ! File . Exists ( Ensure . NotEmptyString ( fullPath , nameof ( fullPath ) ) ) )
87
- throw new FileNotFoundException ( "File not found" , fullPath ) ;
91
+ public static FileParameter FromFile ( string fullPath , string ? name = null , string ? contentType = null , FileParameterOptions ? options = null ) {
92
+ if ( ! File . Exists ( Ensure . NotEmptyString ( fullPath , nameof ( fullPath ) ) ) ) throw new FileNotFoundException ( "File not found" , fullPath ) ;
88
93
89
- var fileName = Path . GetFileName ( fullPath ) ;
94
+ var fileName = Path . GetFileName ( fullPath ) ;
90
95
var parameterName = name ?? fileName ;
91
-
92
- return new FileParameter ( parameterName , fileName , GetFile , contentType ) ;
96
+
97
+ return new FileParameter ( parameterName , fileName , GetFile , contentType , options ?? new FileParameterOptions ( ) ) ;
93
98
94
99
Stream GetFile ( ) => File . OpenRead ( fullPath ) ;
95
100
}
96
- }
101
+ }
102
+
103
+ [ PublicAPI ]
104
+ public class FileParameterOptions {
105
+ public bool DisableFileNameStar { get ; set ; } = true ;
106
+ public bool DisableFilenameEncoding { get ; set ; }
107
+ }
0 commit comments