I'm trying to make an upload utility to load an excel file and make a bulk insert into DB.
I'm using AngularJS and Spring.
I've been trying for days, but I can't get java to read the uploaded file.
I'm using ngFileUpload
and javascript is getting my file, but when I call my Controller the param is null or whatever the http error is the 400 "Required request part 'file' is not present".
I tried everything, adding the multipartresolver
into config; enabling the multipart encoding into application.properties; adding the library into the pom.xml
, but it still doesn't works.
server.port=8081
spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled=true
spring.http.multipart.max-file-size=15000000
spring.http.multipart.max-request-size=15000000
@Bean
public MultipartResolver multipartResolver() {
return new CommonsMultipartResolver();
}
@PostMapping(value = "/excelUploader", consumes = "multipart/form-data")
public ResponseEntity<?> saveEnvironmentConfig(@RequestParam("file") MultipartFile submissions){
return null;
}
EDIT Client Side Part
$scope.upload = function() {
Upload.upload({
url: $scope.uploadServiceUrl,
data: { file: $scope.files,
method: 'POST'}
}).then(function(resp) {
if ($scope.uploadCompleteFn) {
$scope.uploadCompleteFn();
}
console.log('Upload complete.');
}, function(resp) {
console.log('Error status: ' + resp.status);
});
};