I'm trying to create a method in C# to add an attachment to an issue, and I'm getting the error `System.Exception: Error adding attachment: UnsupportedMediaType`.
This is my code.
public async Task AddAttachmentAsync(string issueKey, string filePath)
{
try
{
var fileData = File.ReadAllBytes(filePath);
var fileName = Path.GetFileName(filePath);
var request = new RestRequest($"/rest/api/3/issue/{issueKey}/attachments", Method.Post);
request.AddFile("file", fileData, fileName, "multipart/form-data");
var response = await _client.ExecuteAsync(request);
if (!response.IsSuccessful)
{
throw new Exception($"Error adding attachment: {response.StatusCode} - {response.Content}");
}
}
catch (Exception ex)
{
throw ex;
}
}