2013-05-31 82 views
0

我想添加附件到一個服務。 這從資料爲準: enter image description hereIndy的MultiPartEntity [德爾福]

我不知道如果一個實體可以在印地添加,如果它能夠在例如用Java來完成:

postRequest.setHeader("X-Atlassian-Token","nocheck"); 
MultipartEntity entity = new MultipartEntity(); 
entity.addPart("file", new FileBody(fileUpload)); 
postRequest.setEntity(entity); 
HttpResponse response = httpClient.execute(postRequest); 

回答

1

發現:

uses IdMultipartFormData 
... 
Stream: TIdMultipartFormDataStream; 

編輯: 對於Jira REST API的這個特殊問題,解決方案將類似於:

針對URL

發帖:BASE_URL +/REST/API/2 /問題/ {issueIdOrKey} /附件

try 
    lHTTP.Request.CustomHeaders.AddValue('X-Atlassian-Token', 'nocheck'); 
    FileSize := lHTTP.Response.ContentLength; 

    FileStrm := TFileStream.Create(AFile, fmOpenRead or fmShareDenyWrite); 
    try 
     if FileSize < FileStrm.Size then 
     begin 
     FileStrm.Position := FileSize; 

     Stream := TIdMultipartFormDataStream.Create; 
     try 
      Stream.AddFile('file', AFile); 

      with lHTTP do 
      begin 
      with Request do 
      begin 
       ContentRangeStart := FileSize + 1; 
       ContentRangeEnd := FileStrm.Size; 
      end; 

      Post(self.BASE_URL + SEND_ATTACHEMENT_TO_AN_ISSUE_URL + 
       IntToStr(IssueID) + '/attachments', Stream); 

      Result := true; 

      end; 
     finally 
      Stream.Free; 
     end; 
     end; 
    finally 
     FileStrm.Free; 
    end; 
    except 
    Result := false; 
    end; 

注:在那之後人們不應該忘記改回了頭,並改變 「內容類型」到未來請求所需的那個