use of com.github.ljtfreitas.julian.http.MediaType in project julian-http-client by ljtfreitas.
the class PathSerializer method write.
@Override
public void write(String boundary, MultipartFormField<Path> field, Charset charset, OutputStream output) {
Path path = field.value;
ContentDisposition contentDisposition = new ContentDisposition(field.name, path.getFileName().toString());
MediaType mediaType = field.contentType.orElseGet(() -> Except.run(() -> Files.probeContentType(path)).map(MediaType::valueOf).recover(() -> MEDIA_TYPE_OCTET_STREAM));
new MultipartFormFieldWriter(output, boundary, contentDisposition, mediaType).write(o -> Files.copy(path, output)).prop(e -> new HTTPRequestWriterException(Message.format("Cannot write multipart/form-data field {0}", field.name), e));
}
Aggregations