2

I implemented this code almost exactly as listed in the examples for HttpBuilder-NG and it is not working for me. For some reason it does not recognize the multipart as a method. Example from the creators of the libraries https://http-builder-ng.github.io/http-builder-ng/asciidoc/html5/#_multipart

def uploadFileNG(String targetTestId, String filePath) {
    File someFile = new File(filePath)
    OkHttpBuilder.configure {
        request.uri = blazeUrl
    }.post {
        request.uri.path = "/api/latest/tests/${targetTestId}/files"
        request.contentType = "multipart/form-data"
        request.body = multipart {
            field 'name', 'This is my file'
            part 'file', someFile.getName(), 'text/plain', someFile
        }
        request.encoder 'multipart/form-data', OkHttpEncoders.&multipart
    }
}
cjstehno
  • 13,468
  • 4
  • 44
  • 56
JJ Welch
  • 23
  • 2
  • The full error message? – aristotll Aug 18 '17 at 03:30
  • groovy.lang.MissingMethodException: No signature of method: com.foulk.utils.blazeapi.BlazeApiHelper.multipart() is applicable for argument types: (com.foulk.utils.blazeapi.BlazeApiHelper$_uploadFileNG_closure9$_closure12) values: [com.foulk.utils.blazeapi.BlazeApiHelper$_uploadFileNG_closure9$_closure12@704deff2] – JJ Welch Aug 18 '17 at 13:21

1 Answers1

1

The multipart method (in request.body config) needs to be statically imported (I will update the docs to be more explicit about this).

This would be import static groovyx.net.http.MultipartContent.multipart for your example.

cjstehno
  • 13,468
  • 4
  • 44
  • 56
  • I thought I had tried that before but apparently I did not. The static import of multipart worked perfectly, thank you for the guidance. – JJ Welch Aug 18 '17 at 13:08
  • I just pushed the doc update as well so others will not fall into the same trap. :-) – cjstehno Aug 18 '17 at 13:15