diff --git a/RestSharp/IRestRequest.cs b/RestSharp/IRestRequest.cs index 7195773d2..63f61e7d8 100644 --- a/RestSharp/IRestRequest.cs +++ b/RestSharp/IRestRequest.cs @@ -139,6 +139,16 @@ public interface IRestRequest /// This request IRestRequest AddFile(string name, string path); + /// + /// Adds a file to the Files collection to be included with a POST or PUT request with the specified content type + /// (other methods do not support file uploads). + /// + /// The parameter name to use in the request + /// Full path to file to upload + /// The MIME type of the file to upload + /// This request + IRestRequest AddFile(string name, string path, string contentType); + /// /// Adds the bytes to the Files collection with the specified file name /// diff --git a/RestSharp/RestRequest.cs b/RestSharp/RestRequest.cs index e0e9e781c..beee330ee 100644 --- a/RestSharp/RestRequest.cs +++ b/RestSharp/RestRequest.cs @@ -141,6 +141,35 @@ public IRestRequest AddFile(string name, string path) }); } + /// + /// Adds a file to the Files collection to be included with a POST or PUT request with the specified content type + /// (other methods do not support file uploads). + /// + /// The parameter name to use in the request + /// Full path to file to upload + /// The MIME type of the file to upload + /// This request + public IRestRequest AddFile(string name, string path, string contentType) + { + FileInfo f = new FileInfo(path); + long fileLength = f.Length; + + return AddFile(new FileParameter + { + Name = name, + FileName = Path.GetFileName(path), + ContentLength = fileLength, + Writer = s => + { + using (var file = new StreamReader(path)) + { + file.BaseStream.CopyTo(s); + } + }, + ContentType = contentType + }); + } + /// /// Adds the bytes to the Files collection with the specified file name ///