#10472 csharp-netcore client - allow to specify content-type for files (#10473)

This commit is contained in:
Eugene 2021-09-26 18:31:37 +03:00 committed by GitHub
parent 119370079a
commit 60b29e1f8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 38 additions and 2 deletions

View File

@ -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);
}

View File

@ -15,6 +15,11 @@ namespace {{packageName}}.Client
/// </summary>
public string Name { get; set; } = "no_name_provided";
/// <summary>
/// The content type of the file
/// </summary>
public string ContentType { get; set; } = "application/octet-stream";
/// <summary>
/// The content of the file
/// </summary>
@ -44,6 +49,19 @@ namespace {{packageName}}.Client
Content = content;
}
/// <summary>
/// Construct a FileParameter from name and content
/// </summary>
/// <param name="filename">The filename</param>
/// <param name="contentType">The content type of the file</param>
/// <param name="content">The file content</param>
public FileParameter(string filename, string contentType, Stream content)
{
Name = filename;
ContentType = contentType;
Content = content;
}
/// <summary>
/// Implicit conversion of stream to file parameter. Useful for backwards compatibility.
/// </summary>

View File

@ -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);
}

View File

@ -23,6 +23,11 @@ namespace Org.OpenAPITools.Client
/// </summary>
public string Name { get; set; } = "no_name_provided";
/// <summary>
/// The content type of the file
/// </summary>
public string ContentType { get; set; } = "application/octet-stream";
/// <summary>
/// The content of the file
/// </summary>
@ -52,6 +57,19 @@ namespace Org.OpenAPITools.Client
Content = content;
}
/// <summary>
/// Construct a FileParameter from name and content
/// </summary>
/// <param name="filename">The filename</param>
/// <param name="contentType">The content type of the file</param>
/// <param name="content">The file content</param>
public FileParameter(string filename, string contentType, Stream content)
{
Name = filename;
ContentType = contentType;
Content = content;
}
/// <summary>
/// Implicit conversion of stream to file parameter. Useful for backwards compatibility.
/// </summary>