spring-boot - 在 Spring Boot 中发送带有多个附件的电子邮件
问题描述
我正在创建一个用于在 Spring Boot 中发送电子邮件的 api。我可以使用以下 api 在电子邮件中成功发送附件
@PostMapping("/send")
public void sendMail(@RequestParam(value = "receiver") String receiver,
@RequestParam(value = "subject") String subject, @RequestParam(value = "content") String content,
@RequestParam(value = "file", required = false) MultipartFile file) {
mailService.send(receiver, subject, content, file);
}
但是一封电子邮件可以有多个附件。因此,使用此链接作为参考,我将代码更新为
@PostMapping("/send")
public void sendMail(@RequestParam(value = "receiver") String receiver,
@RequestParam(value = "subject") String subject, @RequestParam(value = "content") String content,
@RequestParam(value = "files", required = false) MultipartFile[] files) {
mailService.send(receiver, subject, content, files);
}
有了这个,我可以从 Swagger UI 添加多个图像
更新:我在 Swagger 中获得以下表格,我可以从中上传图片
但是当我提交表单时,我发现 files 中的值现在为 null 而不是文件数组。
我错过了什么?
解决方案
正如@MebinJoe 提到的,这是招摇的问题。无法用 swagger 解决问题,但最终使用 Postman 来测试上面的代码。多个文件已成功附加并通过电子邮件发送。
推荐阅读
- ios - UDID 格式无效 iPhone X、Xs(24 个字符,带破折号)
- c# - WPF BIND 通过位图资源动态绑定图像
- .net-core - asp.net 核心 uri 编码
- nginx - 基于referer的nginx条件路由
- sql-server - Correct way to convert Month Name and Year to complete date SQL Server
- java - JavaFX 中的 ClassCastException
- c# - 如何在不改变当前线程文化的情况下将 dateTimeOffset 从 Hijri 转换为 Gregorian?
- blockchain - 如何使用 web3 在以太坊中获取待处理的交易?
- javascript - react-native ios如何使用android按钮
- python - 将新字符串添加到文本文件中特定行的末尾