use of oap.util.Maps.Collectors.toMap in project oap by oaplatform.
the class Client method uploadFile.
@SneakyThrows
public Response uploadFile(String uri, String prefix, Path path) {
final ContentType contentType = ContentType.create(java.nio.file.Files.probeContentType(path));
OkHttpClient client = new OkHttpClient();
final MultipartBody body = new MultipartBody.Builder().setType(MultipartBody.FORM).addFormDataPart("upfile", path.toFile().getName(), RequestBody.create(MediaType.parse(contentType.toString()), path.toFile())).addFormDataPart("prefix", prefix).build();
okhttp3.Request request = new okhttp3.Request.Builder().url(uri).post(body).build();
final okhttp3.Response response = client.newCall(request).execute();
final Headers headers = response.headers();
final java.util.stream.Stream<String> stream = headers.names().stream();
final Map<String, String> h = stream.collect(Collectors.toMap(n -> n, headers::get));
return new Response(response.code(), response.message(), h, Optional.ofNullable(response.body().contentType()).map(mt -> ContentType.create(mt.type() + "/" + mt.subtype(), mt.charset())), response.body().bytes());
}
Aggregations