Skip to content

Commit

Permalink
#10472 csharp-netcore client - allow to specify content-type for files (
Browse files Browse the repository at this point in the history
  • Loading branch information
llRandom committed Sep 26, 2021
1 parent 1193700 commit 60b29e1
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ HttpContent PrepareMultipartFormDataContent(RequestOptions options)
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ public class FileParameter
/// </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>
Expand Down Expand Up @@ -52,6 +57,19 @@ public FileParameter(string filename, Stream content)
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>
Expand Down

0 comments on commit 60b29e1

Please sign in to comment.