[英]JIRA rest api attaching attachment with the issue. how to set MIME type
i have successfully attached an image with the issue using JIRA rest API in c# console application. 我已经在c#控制台应用程序中使用JIRA rest API成功附加了带有问题的图像。 but when i see the issue in jira it gives me error. 但是当我看到jira中的问题时,它给了我错误。
Error rendering 'com.atlassian.jira.jira-view-issue-plugin:attachmentmodule'. Please contact your JIRA administrators.
on searching this issue on the internet. 在互联网上搜索此问题。 the possible problem seems with the MIME type. MIME类型可能出现了问题。 when i watch the issue using rest api.(using rest api client postman) 当我使用rest api观看问题时(使用rest api客户端邮递员)
here is my out put 这是我的输出
"attachment": [
{
"self": "http://localhost:8080/rest/api/2/attachment/10103",
"id": "10103",
"filename": "images.jpg",
"author": {
"self": "http://localhost:8080/rest/api/2/user?username=wayne",
"name": "wayne",
"emailAddress": "brucewayne@waynecorp.com",
"avatarUrls": {
"16x16": "http://www.gravatar.com/avatar/faf8b9c4d44a4d05ca963d512c8d8805?d=mm&s=16",
"24x24": "http://www.gravatar.com/avatar/faf8b9c4d44a4d05ca963d512c8d8805?d=mm&s=24",
"32x32": "http://www.gravatar.com/avatar/faf8b9c4d44a4d05ca963d512c8d8805?d=mm&s=32",
"48x48": "http://www.gravatar.com/avatar/faf8b9c4d44a4d05ca963d512c8d8805?d=mm&s=48"
},
"displayName": "The Batman",
"active": true
},
"created": "2014-07-24T12:53:06.080+0530",
"size": 13303,
"content": "http://localhost:8080/secure/attachment/10103/images.jpg",
"thumbnail": "http://localhost:8080/secure/thumbnail/10103/_thumb_10103.png"
}
]
here i see 我在这里看到
"mimeType": "image/jpeg" missing in the attachment array. “ mimeType”:附件数组中缺少“ image / jpeg”。
and i want to know where to add this mime type in my request. 我想知道在我的请求中在何处添加此mime类型。 my code is as follows 我的代码如下
string postUrl = "http://localhost:8080/rest/api/latest/issue/" + projKey + "/attachments";
System.Net.Http.HttpClient client = new System.Net.Http.HttpClient();
client.DefaultRequestHeaders.Add("X-Atlassian-Token", "nocheck");
client.BaseAddress = new System.Uri(postUrl);
byte[] cred = UTF8Encoding.UTF8.GetBytes(credentials);
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(cred));
MultipartFormDataContent content = new MultipartFormDataContent();
HttpContent fileContent = new ByteArrayContent(File.ReadAllBytes(filePath));
/*
content.Headers.ContentType= new MediaTypeHeaderValue("content-type")
{
MediaType = System.Net.Mime.MediaTypeNames.Image.Jpeg
}; */
content.Add(fileContent, "file", fileName);
var result = client.PostAsync(postUrl, content).Result;
Please suggest me a solution. 请给我建议一个解决方案。 i want to use httpclient for sending request 我想使用httpclient发送请求
i found the solution. 我找到了解决方案。 i was correct issue was related to the MIME type. 我是正确的问题与MIME类型有关。 for MultipartFormDataContent i need to give it as follows (Rest of code is written above). 对于MultipartFormDataContent,我需要给它如下(其余代码在上面编写)。
HttpContent fileContent = new ByteArrayContent(File.ReadAllBytes(filePath)
string mimeType = System.Web.MimeMapping.GetMimeMapping(fileName);
//specifying MIME Type
fileContent.Headers.ContentType = MediaTypeHeaderValue.Parse(mimeType);
content.Add(fileContent, "file",fileName);
var result = client.PostAsync(postUrl, content).Result;
this fixed the problem. 这解决了问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.