File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -139,6 +139,16 @@ public interface IRestRequest
139
139
/// <returns>This request</returns>
140
140
IRestRequest AddFile ( string name , string path ) ;
141
141
142
+ /// <summary>
143
+ /// Adds a file to the Files collection to be included with a POST or PUT request with the specified content type
144
+ /// (other methods do not support file uploads).
145
+ /// </summary>
146
+ /// <param name="name">The parameter name to use in the request</param>
147
+ /// <param name="path">Full path to file to upload</param>
148
+ /// <param name="contentType">The MIME type of the file to upload</param>
149
+ /// <returns>This request</returns>
150
+ IRestRequest AddFile ( string name , string path , string contentType ) ;
151
+
142
152
/// <summary>
143
153
/// Adds the bytes to the Files collection with the specified file name
144
154
/// </summary>
Original file line number Diff line number Diff line change @@ -141,6 +141,35 @@ public IRestRequest AddFile(string name, string path)
141
141
} ) ;
142
142
}
143
143
144
+ /// <summary>
145
+ /// Adds a file to the Files collection to be included with a POST or PUT request with the specified content type
146
+ /// (other methods do not support file uploads).
147
+ /// </summary>
148
+ /// <param name="name">The parameter name to use in the request</param>
149
+ /// <param name="path">Full path to file to upload</param>
150
+ /// <param name="contentType">The MIME type of the file to upload</param>
151
+ /// <returns>This request</returns>
152
+ public IRestRequest AddFile ( string name , string path , string contentType )
153
+ {
154
+ FileInfo f = new FileInfo ( path ) ;
155
+ long fileLength = f . Length ;
156
+
157
+ return AddFile ( new FileParameter
158
+ {
159
+ Name = name ,
160
+ FileName = Path . GetFileName ( path ) ,
161
+ ContentLength = fileLength ,
162
+ Writer = s =>
163
+ {
164
+ using ( var file = new StreamReader ( path ) )
165
+ {
166
+ file . BaseStream . CopyTo ( s ) ;
167
+ }
168
+ } ,
169
+ ContentType = contentType
170
+ } ) ;
171
+ }
172
+
144
173
/// <summary>
145
174
/// Adds the bytes to the Files collection with the specified file name
146
175
/// </summary>
You can’t perform that action at this time.
0 commit comments