Search code examples
postgroovymultiparthttpbuilder-ng

httpbuilder-ng no signature of method multipart() when attempting a post


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
    }
}

Solution

  • 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.