업로드 요청 추가

master
mjkhan21 10 months ago
parent b24477a01b
commit fd2c935ae1

@ -268,6 +268,32 @@ public class WebClient extends AbstractComponent {
}
}
/** .
* @param <T> body
* @param configurer
* @return http
*/
@SuppressWarnings("unchecked")
public <T> HttpResponse<T> upload(Consumer<Request> configurer) {
Request req = new Request().multipart();
req.charset = charset();
configurer.accept(req);
HttpRequest hreq = req.post();
try {
if (req.download)
return (HttpResponse<T>)handleRequest(req.async, hreq, HttpResponse.BodyHandlers.ofInputStream(), req.downloadHandler);
else
return (HttpResponse<T>)handleRequest(req.async, hreq, HttpResponse.BodyHandlers.ofString(), req.textHandler);
} catch (Throwable e) {
if (req.async) {
req.errorHandler.accept(rootCause(e));
return null;
} else
throw runtimeException(e);
}
}
/** , .
* @param inputStream
* @param path
@ -432,6 +458,13 @@ public class WebClient extends AbstractComponent {
return contentType(ContentType.JSON);
}
/**content-type .
* @return Request
*/
public Request multipart() {
return contentType(ContentType.MULTIPART);
}
private JSON json() {
return ifEmpty(json, () -> json = new JSON());
}

Loading…
Cancel
Save