Skip to content

Commit

Permalink
✨ 完善 mica-http,方便下载的文件再上传的场景
Browse files Browse the repository at this point in the history
  • Loading branch information
li-xunhuan committed Dec 15, 2023
1 parent 577754a commit 81fc56a
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions mica-http/src/main/java/net/dreamlu/mica/http/ResponseSpec.java
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,28 @@ default <T> List<T> atJsonPathList(String jsonPtrExpr, Class<T> valueType) {
*/
<V> Map<String, V> 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.
*
Expand Down

0 comments on commit 81fc56a

Please sign in to comment.