Install a plugin via groovy - Content length is too long: 119800

I’m trying to install a plugin from jar file.
Using curl and multipart/form-data (-F flag) I’m able to do it.

url="http://admin:admin@localhost:8080/rest/plugins/1.0/"
token=$(curl -sI "$url?os_authType=basic" | grep upm-token | cut -d: -f2- | tr -d '[[:space:]]')
curl -XPOST "$url?token=$token" -F plugin=@/my-plugin.jar

I’d like to do the same using HttpBuilder-ng
https://http-builder-ng.github.io/http-builder-ng/asciidoc/html5/#_multipart

import static groovyx.net.http.HttpBuilder.configure

File jar = new File('/my-plugin.jar')

configure {
            request.uri = "http:/localhost:8080"
        }.post() {

            request.headers = [
                    'X-Atlassian-Token': "no-check",
                    'Authorization'    : "Basic ${authString}",
            ]

            request.contentType = 'multipart/form-data'
            request.uri.path = "/rest/plugins/1.0/"
            request.uri.query = [token: upmToken]

            request.encoder 'multipart/form-data', ApacheEncoders.&multipart


            request.body = multipart {
                part 'plugin', "my-plugin.jar", 'application/octet-stream', jar
            }

I’m getting an exception

org.apache.http.ContentTooLongException: Content length is too long: 119800
at org.apache.http.entity.mime.MultipartFormEntity.getContent(MultipartFormEntity.java:103)

Anyone got a working sample?

OK I’ve replaced the apache implementation:
compile 'io.github.http-builder-ng:http-builder-ng-apache:1.0.3'

with OKhttp implementation
compile 'io.github.http-builder-ng:http-builder-ng-okhttp:1.0.3'

And everything works like a charm :slight_smile: