如何在VSCode RestClient的POST请求中发送名为productImages的文件数组
RestClient发起多文件上传请求(适配Multer productImages字段)
可用请求模板
直接将以下内容保存为.rest后缀的文件,在VSCode中用RestClient插件打开即可运行:
POST http://你的后端接口地址 HTTP/1.1 Content-Type: multipart/form-data; boundary=----CustomBoundary123456 ------CustomBoundary123456 Content-Disposition: form-data; name="productImages"; filename="示例图片1.jpg" Content-Type: image/jpeg < /你本地的文件存储路径/示例图片1.jpg ------CustomBoundary123456 Content-Disposition: form-data; name="productImages"; filename="示例图片2.png" Content-Type: image/png < /你本地的文件存储路径/示例图片2.png ------CustomBoundary123456 Content-Disposition: form-data; name="productImages"; filename="示例图片3.webp" Content-Type: image/webp < /你本地的文件存储路径/示例图片3.webp ------CustomBoundary123456--
配置说明
- 所有文件对应的
form字段名必须统一为productImages,和Multer侧配置的接收参数完全一致,Multer才能正确识别为文件数组 boundary值可自定义,只需保证请求头声明的boundary和请求体中分隔符的前缀完全匹配即可- 本地文件路径支持绝对路径和相对路径(相对路径相对于当前
.rest文件所在目录) - 如需额外传递其他表单参数,可在分隔符块中添加对应字段,示例如下:
------CustomBoundary123456 Content-Disposition: form-data; name="productName" 新款运动鞋
内容的提问来源于stack exchange,提问作者Lakmal Fernando
相关产品推荐
相关产品推荐

