From 81fc56a5d9ba03e3b08e2ea50564358ca80b8e30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C7=B3=C3=83=C3=8E?= <1101766085@qq.com> Date: Fri, 15 Dec 2023 10:41:52 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E5=AE=8C=E5=96=84=20mica-http?= =?UTF-8?q?=EF=BC=8C=E6=96=B9=E4=BE=BF=E4=B8=8B=E8=BD=BD=E7=9A=84=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=86=8D=E4=B8=8A=E4=BC=A0=E7=9A=84=E5=9C=BA=E6=99=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../net/dreamlu/mica/http/ResponseSpec.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/mica-http/src/main/java/net/dreamlu/mica/http/ResponseSpec.java b/mica-http/src/main/java/net/dreamlu/mica/http/ResponseSpec.java index d0e250c69..0c8b94023 100644 --- a/mica-http/src/main/java/net/dreamlu/mica/http/ResponseSpec.java +++ b/mica-http/src/main/java/net/dreamlu/mica/http/ResponseSpec.java @@ -294,6 +294,28 @@ default List atJsonPathList(String jsonPtrExpr, Class valueType) { */ Map asMap(Class valueType); + /** + * 转换成文件上传 part + * + * @param name 表单名 + * @return Part + */ + default MultipartBody.Part asPart(String name) { + return asPart(name, null); + } + + /** + * 转换成文件上传 part + * + * @param name 表单名 + * @param fileName 文件名 + * @return Part + */ + default MultipartBody.Part asPart(String name, @Nullable String fileName) { + RequestBody requestBody = RequestBody.create(asBytes(), contentType()); + return MultipartBody.Part.createFormData(name, fileName, requestBody); + } + /** * toFile. *