1
0
-1

Hi,

I'm building a Fluent Delivery service to add attachments (pdf receipt and other attachments) to a JIRA issue.

JIRA documentation says that 'this resource expects a multi part post. and that the Apache http components has a MultiPartEntity that makes it simple to submit a multi part POST.

However, the type-check task returns an error to say that:

Importing org.apache.http.entity.mime.MultiPartEntityBuilder is not allowed.

is it neccessary to use the MultiPartEntityBuilder, or is it sufficient to use the "addFileParam" methoid of the PostRequest?

any guidance would be appreciated.

Thanks

Mark

    CommentAdd your comment...

    3 answers

    1.  
      1
      0
      -1

      Hi Bill,

      I've written a service using the 'addFileParam' method, however I am getting an error that says: 

      org.apache.commons.fileupload.FileUploadException: the request was rejected because no multipart boundary was found


      I'm following the JIRA instructions here: issue - addAttachment

      and this is the method I'm using to add attachments:

      resource = "issue/${jiraIssueKey}/attachments"
      
      
      String addAttachments(String resource, byte[] data, String fileName) {
          String uri = "${endpoint}/${API}/${resource}"
          try {
              HttpResponse response = new PostRequest(uri)
                      .addHeader("Content-type", "multipart/form-data")
                      .addHeader("X-Atlassian-Token", "no-check")
                      .addFileParam("file", data, fileName)
                      .setBasicAuth(username, password)
                      .execute()
      
              if (response.isSuccess()) {
                  logger.debug("<< result.status    : ${response.statusLine}")
                  return response.getTextContent()
              } else {
                  String errorMessage = "## ERROR            : ${response.statusLine} - ${response.getTextContent()}"
                  new EventLogger().setTxn(txn).setMessage(errorMessage).logError()
                  logger.error(errorMessage)
                  return errorMessage
              }
      
          } catch (Exception e) {
              throw new Exception("JIRA.addAttachments() Exception", e)
          } finally {
              // log service call
              if (txn) {
                  String info = "JIRA.addAttachments - ${uri}"
                  new TxnUpdater(txn).addServiceCallLog(SERVICE_NAME, info, endpoint).update()
              }
          }
      }

      I create the JIRA issue in one checkpoint, then if the issue is successfully created I add the attachments in another checkpoint.


      any ideas about how to solve the mulit part boudary issue?


      Thanks

      Mark

      1. Mark Murray

        YES! it works.

        That is not what I was expecting would solve the problem.

        Thanks for your help; making great progress on this now.

        Much appreciated.

        Thanks

      2. Bill Frost

        No problem Mark... glad to be of help.

      CommentAdd your comment...
    2.  
      1
      0
      -1

      Hi Mark,

      Does it work if you remove the line '.addHeader("Content-type", "multipart/form-data")' ?

        CommentAdd your comment...
      1.  
        1
        0
        -1

        Hi Mark,

        PostRequest.addFileParam uses MultiPartEntityBuilder internally, so addFileParam is all you need.

        1. Mark Murray

          Hi Bill,

          thanks for the quick response. That's good to know. The rest of my code is type safe, so I should be able to make some progress after removing the MultiPartEntityBuilder.

          Thanks

          Mark

        CommentAdd your comment...