2014-07-24 3 views
0

C# 콘솔 응용 프로그램의 JIRA 나머지 API를 사용하여 문제가있는 이미지를 성공적으로 첨부했습니다. 하지만 jira에서 문제가 발생하면 오류가 발생합니다.JIRA 휴식 API 첨부 첨부. MIME 유형을 설정하는 방법

Error rendering 'com.atlassian.jira.jira-view-issue-plugin:attachmentmodule'. Please contact your JIRA administrators. 

인터넷에서이 문제를 검색하고 있습니다. 가능한 문제는 MIME 형식과 같습니다. . "이미지/JPEG"첨부 파일에서 누락 : 난 나머지 API를 사용하여 문제를 볼 때 (나머지 API 클라이언트 우체부를 사용하여) 여기

내 밖으로 내가
이 "MIME 타입"을 참조하십시오 여기
"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": "[email protected]", 
       "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" 
     } 
    ] 

을 넣어이다 정렬.

그리고 내 요청에이 마임 유형을 추가 할 위치를 알고 싶습니다.

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; 

나에게 해결책을 제안하십시오 다음과 같이 내 코드입니다. 요청을 보내기 위해 httpclient를 사용하고 싶습니다.

답변

0

해결책을 찾았습니다. 올바른 문제는 MIME 형식과 관련이 있습니다. 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; 

이 문제가 해결되었습니다.

관련 문제