Example usage for com.squareup.okhttp MultipartBuilder addPart

List of usage examples for com.squareup.okhttp MultipartBuilder addPart

Introduction

In this page you can find the example usage for com.squareup.okhttp MultipartBuilder addPart.

Prototype

public MultipartBuilder addPart(RequestBody body) 

Source Link

Document

Add a part to the body.

Usage

From source file:com.wialon.remote.OkSdkHttpClient.java

License:Apache License

@Override
public void postFile(String url, Map<String, String> params, Callback callback, int timeout, File file) {
    //Method will work at 2.1 version of library https://github.com/square/okhttp/issues/963 and https://github.com/square/okhttp/pull/969
    MultipartBuilder builder = new MultipartBuilder();
    builder.type(MultipartBuilder.FORM);
    RequestBody paramsBody = paramsMapToRequestBody(params);
    if (paramsBody != null) {
        builder.addPart(paramsBody);
    }//  www.  j a v a2 s. c  o  m
    builder.addPart(RequestBody.create(MediaType.parse(""), file));
    Request request = new Request.Builder().url(url).post(builder.build()).build();
    threadPool.submit(new HttpRequest(getHttpClient(timeout), request, callback));
}