I try to upload a song with postman but I have a error like the The field song exceeds its maximum permitted size of 1048576 bytes."
I already tried to add this configurations in the application.properties files but it doesn't work :
spring.servlet.multipart.max-file-size=10MB spring.servlet.multipart.max-request-size=10MB
I precise that's work with files which size is < 1048576 bytes
This is my Controller:
@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");
}
This is my service:
@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()));
}
}
}
This is my message with the error: {"timestamp":"2018-10-10T13:27:07.090+0000","status":500,"error":"Internal Server Error","message":"Maximum upload size exceeded; nested exception is java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException: The field song exceeds its maximum permitted size of 1048576 bytes.","path":"/music-service/songs"}
I use microservices and my configuration is on gitLab and is this one:
I use postman with like this to insert i file:
For spring-boot version 2.x.x give a try with below code by including http.
spring.http.multipart.max-file-size=300MB
spring.http.multipart.max-request-size=300MB
Refer set-maxfilesize
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With