【发布时间】:2019-03-15 10:32:36
【问题描述】:
我尝试使用邮递员上传歌曲,但出现类似 字段歌曲超出其允许的最大大小 1048576 字节的错误。"
我已经尝试在 application.properties 文件中添加此配置,但它不起作用:
spring.servlet.multipart.max-file-size=10MB spring.servlet.multipart.max-request-size=10MB
确切地说,这适用于大小为
这是我的控制器:
@PostMapping("/songs")
public ResponseEntity<?> insertSong( @RequestParam(value = "title") String title, @RequestParam(value = "song") MultipartFile file) throws IOException {
Song song= new Song(title);
songService.insertSong(song, file);
return ResponseEntity.ok("song inserted");
}
这是我的服务:
@Service
public class SongServiceImpl implements SongService {
@Autowired
SongRepository songRepository;
@Value("${dir.songs}")
private String songsFolderPath;
@Override
public void insertSong(Song song, MultipartFile file) throws IOException
{
if(!(file.isEmpty())){
song.setSongPath(file.getOriginalFilename());
songRepository.save(song);
if (!(file.isEmpty())){
song.setSongPath(file.getOriginalFilename());
file.transferTo(new
File(songsFolderPath+song.getSong_ID()));
}
}
}
这是我的错误消息: {"timestamp":"2018-10-10T13:27:07.090+0000","status":500,"error":"Internal Server Error","message":"最大上传大小超出;嵌套异常is java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException: 现场歌曲超过其最大允许大小 1048576 字节。","path":"/music-service/songs"}
我使用微服务,我的配置在 gitLab 上,是这个:
我使用 postman 来插入 i 文件:
【问题讨论】:
-
您能告诉我们更多关于您的 Spring Boot 版本的信息吗?
-
在我的情况下没有答案
-
@flyordie 你找到答案了吗?
标签: spring spring-boot