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. *