IDEA HTTP Client 上传文件

IDEA HTTP Client About 867 words

HTTP Client 代码

POST http://localhost:8080/upload
Content-Type: multipart/form-data; boundary=boundary

--boundary
Content-Disposition: form-data; name="file"; filename="a.txt"

< C:\a.txt

--boundary
Content-Disposition: form-data; name="extraInfo";

this is extra info

快捷键

可以使用mptr生成HTTP Client模版。

后端代码

@RestController
public class UploadController {

    @PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public Object simpleUpload(@RequestPart("file") MultipartFile file, @RequestParam("extraInfo") String extraInfo) {
        // ...
    }
}

说明

form-data; name="file";中的file是指定上传文件的字段名(Spring MultipartFile指定的接收字段名),filename="a.txt"MultipartFile中获取到的文件名)。

form-data; name="extraInfo";中的extraInfo是接收的额外参数,对应@RequestParam("extraInfo")

官方文档

https://www.jetbrains.com/help/idea/exploring-http-syntax.html#use-multipart-form-data

Views: 1,675 · Posted: 2023-05-30

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh