List of usage examples for com.squareup.okhttp MultipartBuilder MultipartBuilder
public MultipartBuilder(String boundary)
From source file:twitter4j.AlternativeHttpClientImpl.java
License:Apache License
private RequestBody getRequestBody(HttpRequest req) throws UnsupportedEncodingException { if (HttpParameter.containsFile(req.getParameters())) { final String boundary = "----Twitter4J-upload" + System.currentTimeMillis(); MultipartBuilder multipartBuilder = new MultipartBuilder(boundary).type(MultipartBuilder.FORM); for (HttpParameter parameter : req.getParameters()) { if (parameter.isFile()) { multipartBuilder.addPart( Headers.of("Content-Disposition", "form-data; name=\"" + parameter.getName() + "\"; filename=\"" + parameter.getFile().getName() + "\""), RequestBody.create(MediaType.parse(parameter.getContentType()), parameter.getFile())); } else { multipartBuilder.addPart( Headers.of("Content-Disposition", "form-data; name=\"" + parameter.getName() + "\""), RequestBody.create(TEXT, parameter.getValue().getBytes("UTF-8"))); }/*from w w w.j ava 2s . co m*/ } return multipartBuilder.build(); } else { return RequestBody.create(FORM_URL_ENCODED, HttpParameter.encodeParameters(req.getParameters()).getBytes("UTF-8")); } }