@@ -20,9 +20,9 @@ namespace RestSharp;
2020[ PublicAPI ]
2121public record FileParameter {
2222 /// <summary>
23- /// Provides raw data for file
23+ /// Name of the parameter
2424 /// </summary>
25- public Func < Stream > GetFile { get ; }
25+ public string Name { get ; }
2626
2727 /// <summary>
2828 /// Name of the file to use when uploading
@@ -35,15 +35,18 @@ public record FileParameter {
3535 public string ? ContentType { get ; }
3636
3737 /// <summary>
38- /// Name of the parameter
38+ /// Provides raw data for file
3939 /// </summary>
40- public string Name { get ; }
40+ public Func < Stream > GetFile { get ; }
41+
42+ public FileParameterOptions Options { get ; }
4143
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 ;
4750 }
4851
4952 /// <summary>
@@ -53,9 +56,10 @@ public record FileParameter {
5356 /// <param name="data">The data to use as the file's contents.</param>
5457 /// <param name="filename">The filename to use in the request.</param>
5558 /// <param name="contentType">The content type to use in the request.</param>
59+ /// <param name="options">File parameter options</param>
5660 /// <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 ( ) ) ;
5963
6064 Stream GetFile ( ) {
6165 var stream = new MemoryStream ( ) ;
@@ -73,24 +77,31 @@ Stream GetFile() {
7377 /// <param name="getFile">Delegate that will be called with the request stream so you can write to it..</param>
7478 /// <param name="fileName">The filename to use in the request.</param>
7579 /// <param name="contentType">Optional: parameter content type, default is "application/g-zip"</param>
80+ /// <param name="options">File parameter options</param>
7681 /// <returns>The <see cref="FileParameter" /> using the default content type.</returns>
7782 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
8288 )
83- => new ( name , fileName , getFile , contentType ?? Serializers . ContentType . Binary ) ;
89+ => new ( name , fileName , getFile , contentType ?? Serializers . ContentType . Binary , options ?? new FileParameterOptions ( ) ) ;
8490
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 ) ;
8893
89- var fileName = Path . GetFileName ( fullPath ) ;
94+ var fileName = Path . GetFileName ( fullPath ) ;
9095 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 ( ) ) ;
9398
9499 Stream GetFile ( ) => File . OpenRead ( fullPath ) ;
95100 }
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