Pregunta

I am trying to add attachement to one service. This taken from documentation: enter image description here

I wonder if an entity can be added in indy as if it could be done in for example 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);
¿Fue útil?

Solución

Found it:

uses IdMultipartFormData
...
Stream: TIdMultipartFormDataStream;

EDITED: For this particular problem with Jira REST API, solution would be something like:

Posting against URL: BASE_URL+/rest/api/2/issue/{issueIdOrKey}/attachments

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;

Note: After that one should not forget to change back the headers and to change the "Content Type" to the one that is needed for future requests

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top