diff --git a/modules/openapi-generator/src/main/resources/csharp-netcore/libraries/httpclient/ApiClient.mustache b/modules/openapi-generator/src/main/resources/csharp-netcore/libraries/httpclient/ApiClient.mustache index c94d7aaeae6..bd7663012f1 100644 --- a/modules/openapi-generator/src/main/resources/csharp-netcore/libraries/httpclient/ApiClient.mustache +++ b/modules/openapi-generator/src/main/resources/csharp-netcore/libraries/httpclient/ApiClient.mustache @@ -279,7 +279,7 @@ namespace {{packageName}}.Client foreach (var fileParam in options.FileParameters) { var content = new StreamContent(fileParam.Value.Content); - content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); + content.Headers.ContentType = new MediaTypeHeaderValue(fileParam.Value.ContentType); multipartContent.Add(content, fileParam.Key, fileParam.Value.Name); } diff --git a/modules/openapi-generator/src/main/resources/csharp-netcore/libraries/httpclient/FileParameter.mustache b/modules/openapi-generator/src/main/resources/csharp-netcore/libraries/httpclient/FileParameter.mustache index 3fa243ed54f..87e5fcdc9af 100644 --- a/modules/openapi-generator/src/main/resources/csharp-netcore/libraries/httpclient/FileParameter.mustache +++ b/modules/openapi-generator/src/main/resources/csharp-netcore/libraries/httpclient/FileParameter.mustache @@ -15,6 +15,11 @@ namespace {{packageName}}.Client /// public string Name { get; set; } = "no_name_provided"; + /// + /// The content type of the file + /// + public string ContentType { get; set; } = "application/octet-stream"; + /// /// The content of the file /// @@ -44,6 +49,19 @@ namespace {{packageName}}.Client Content = content; } + /// + /// Construct a FileParameter from name and content + /// + /// The filename + /// The content type of the file + /// The file content + public FileParameter(string filename, string contentType, Stream content) + { + Name = filename; + ContentType = contentType; + Content = content; + } + /// /// Implicit conversion of stream to file parameter. Useful for backwards compatibility. /// diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClient-httpclient/src/Org.OpenAPITools/Client/ApiClient.cs b/samples/client/petstore/csharp-netcore/OpenAPIClient-httpclient/src/Org.OpenAPITools/Client/ApiClient.cs index 4ef5e9ead3b..b6d9195b3f6 100644 --- a/samples/client/petstore/csharp-netcore/OpenAPIClient-httpclient/src/Org.OpenAPITools/Client/ApiClient.cs +++ b/samples/client/petstore/csharp-netcore/OpenAPIClient-httpclient/src/Org.OpenAPITools/Client/ApiClient.cs @@ -278,7 +278,7 @@ namespace Org.OpenAPITools.Client foreach (var fileParam in options.FileParameters) { var content = new StreamContent(fileParam.Value.Content); - content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); + content.Headers.ContentType = new MediaTypeHeaderValue(fileParam.Value.ContentType); multipartContent.Add(content, fileParam.Key, fileParam.Value.Name); } diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClient-httpclient/src/Org.OpenAPITools/Client/FileParameter.cs b/samples/client/petstore/csharp-netcore/OpenAPIClient-httpclient/src/Org.OpenAPITools/Client/FileParameter.cs index 4a83ada8588..6d173fe9b3b 100644 --- a/samples/client/petstore/csharp-netcore/OpenAPIClient-httpclient/src/Org.OpenAPITools/Client/FileParameter.cs +++ b/samples/client/petstore/csharp-netcore/OpenAPIClient-httpclient/src/Org.OpenAPITools/Client/FileParameter.cs @@ -23,6 +23,11 @@ namespace Org.OpenAPITools.Client /// public string Name { get; set; } = "no_name_provided"; + /// + /// The content type of the file + /// + public string ContentType { get; set; } = "application/octet-stream"; + /// /// The content of the file /// @@ -52,6 +57,19 @@ namespace Org.OpenAPITools.Client Content = content; } + /// + /// Construct a FileParameter from name and content + /// + /// The filename + /// The content type of the file + /// The file content + public FileParameter(string filename, string contentType, Stream content) + { + Name = filename; + ContentType = contentType; + Content = content; + } + /// /// Implicit conversion of stream to file parameter. Useful for backwards compatibility. ///