Skip to content

Commit

Permalink
Define content-type header in IssuesService.AttachFileToIssue #87
Browse files Browse the repository at this point in the history
  • Loading branch information
maartenba committed Jul 8, 2019
1 parent ab6bfc8 commit 7ec33fa
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/YouTrackSharp/Issues/IIssuesService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,10 @@ Task<ICollection<Issue>> GetIssuesInProject(string projectId, string filter = nu
/// <param name="attachmentStream">The <see cref="T:System.IO.Stream"/> to attach.</param>
/// <param name="group">Attachment visibility group.</param>
/// <param name="author">Creator of the attachment. Note to define author the 'Low-Level Administration' permission is required.</param>
/// <param name="attachmentContentType">Content type of the attachment, for example text/plain or image/png.</param>
/// <exception cref="T:System.ArgumentNullException">When the <paramref name="issueId"/>, <paramref name="attachmentName"/> or <paramref name="attachmentStream"/> is null or empty.</exception>
/// <exception cref="T:System.Net.HttpRequestException">When the call to the remote YouTrack server instance failed.</exception>
Task AttachFileToIssue(string issueId, string attachmentName, Stream attachmentStream, string group = null, string author = null);
Task AttachFileToIssue(string issueId, string attachmentName, Stream attachmentStream, string group = null, string author = null, string attachmentContentType = null);

/// <summary>
/// Get attachments for a specific issue from the server.
Expand Down
6 changes: 5 additions & 1 deletion src/YouTrackSharp/Issues/IssuesService.Attachments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace YouTrackSharp.Issues
public partial class IssuesService
{
/// <inheritdoc />
public async Task AttachFileToIssue(string issueId, string attachmentName, Stream attachmentStream, string group = null, string author = null)
public async Task AttachFileToIssue(string issueId, string attachmentName, Stream attachmentStream, string group = null, string author = null, string attachmentContentType = null)
{
if (string.IsNullOrEmpty(issueId))
{
Expand Down Expand Up @@ -45,6 +45,10 @@ public async Task AttachFileToIssue(string issueId, string attachmentName, Strea
var query = string.Join("&", queryString);

var streamContent = new StreamContent(attachmentStream);
if (!string.IsNullOrEmpty(attachmentContentType))
{
streamContent.Headers.ContentType = MediaTypeHeaderValue.Parse(attachmentContentType);
}
streamContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
{
FileName = attachmentName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public async Task Valid_Connection_Attaches_Single_File_To_Issue()
// Act & Assert
using (var attachmentStream = await TestUtilities.GenerateAttachmentStream("Generated by unit test."))
{
await service.AttachFileToIssue(temporaryIssueContext.Issue.Id, "singlefile.txt", attachmentStream);
await service.AttachFileToIssue(temporaryIssueContext.Issue.Id, "singlefile.txt", attachmentStream, attachmentContentType: "text/plain");
}

await temporaryIssueContext.Destroy();
Expand Down

0 comments on commit 7ec33fa

Please sign in to comment.