我试着用邮递员上传一首歌,但是我有一个错误,比如场歌超过了允许的最大大小1048576字节."
我已经尝试在application.properties文件中添加此配置,但它不起作用:
spring.servlet.multipart.max-file-size = 10MB spring.servlet.multipart.max-request-size = 10MB
我确切地说,这适用于大小<1048576字节的文件
这是我的控制器:
@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");
}
Run Code Online (Sandbox Code Playgroud)
这是我的服务:
@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()));
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的错误消息: {"timestamp":"2018-10-10T13:27:07.090 + 0000","status":500,"error":"内部服务器错误","消息":"最大上传超出大小;嵌套异常是java.lang.IllegalStateException:org.apache.tomcat.util.http.fileupload.FileUploadBase $ FileSizeLimitExceededException:场曲超过其最大允许大小1048576字节.","path":"/ …