Skip to content

Commit 3d39525

Browse files
committed
feat(内核): 支持 Part MIME 类型
1 parent 7e17fa3 commit 3d39525

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

docs/content/usage/part.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,16 @@ String apply(@Part("image") File image);
4646
文件上传请求会自动设置 `Content-Type` 为 `multipart/form-data`,并将文件作为表单的一部分上传。
4747

4848
!!!
49-
```
49+
50+
### `mime` 类型
51+
52+
---
53+
54+
`@Part` 注解支持 `mime` 参数,用于指定上传文件的 MIME 类型,默认值为 `application/octet-stream`
55+
56+
```java
57+
@Post("/upload")
58+
String apply(@Part(value = "image", mime = "image/jpeg") File image);
59+
```
60+
61+
该示例中的 `apply` 方法用于上传图片文件,参数 `image` 表示要上传的图片文件,请求路径是 `/upload`,文件的 MIME 类型是 `image/jpeg`

docs/pageforge.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,23 @@ repo:
88
owner: devlive-community
99
name: lightcall
1010
url: https://github.com/devlive-community/lightcall
11+
branch: dev-2025.1.1
12+
13+
feature:
14+
view:
15+
enable: true
16+
edit:
17+
enable: true
18+
issues:
19+
enable: true
20+
tooltip:
21+
enable: true
22+
revision:
23+
enable: true
24+
contributors:
25+
enable: true
26+
backToTop:
27+
enable: true
1128

1229
footer:
1330
copyright: © 2024 PageForge All Rights Reserved.

lightcall-core/src/main/java/org/devlive/lightcall/annotation/Part.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@
1515
* 文件参数的名称
1616
*/
1717
String value();
18+
19+
String mime() default "application/octet-stream";
1820
}

lightcall-core/src/main/java/org/devlive/lightcall/handler/PartHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public String handle(Parameter parameter, Object arg, String path)
5858

5959
RequestBody fileBody = RequestBody.create(
6060
file,
61-
MediaType.parse("application/octet-stream")
61+
MediaType.parse(partAnnotation.mime())
6262
);
6363

6464
multipartBuilder.addFormDataPart(

0 commit comments

Comments
 (0)