Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[csharp-netcore] allow to specify content-type for files #10473

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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