I'm having trouble sending client side files (images, pdfs) to the server side of my app.
Whenever I try to send a file, Spring gives me this exception:
status:"Bad Request"
exception:"org.springframework.web.multipart.support.MissingServletRequestPartException"
message:"Required request part 'file' is not present"
path:"/upload"
status:400
The Spring controller looks like this:
@RestController
@RequestMapping("/upload")
public class UploadController {
@RequestMapping(value = "",
method = RequestMethod.POST)
public ResponseEntity<?> uploadFile(@RequestParam("file") MultipartFile file) {
try {
if(file != null) {
System.out.println("Arqiuivo recebido!");
}
}
catch (Exception e) {
System.out.println("Deu erro!");
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
return new ResponseEntity<>(HttpStatus.OK);
}
}
And I also configured Multipart to solve like this:
@Bean
public MultipartResolver multipartResolver() {
return new CommonsMultipartResolver();
}
On the client side, as I'm using the ng-file-upload
module, I'm using the following div that appears in the developer's github:
<div class="button" ngf-select ng-model="imagem" name="file" ngf-pattern="'image/*'"
ngf-accept="'image/*'" ngf-max-size="20MB" ngf-min-height="100"
ngf-resize="{width: 100, height: 100}">Select
</div>
And in the AngularJS controller, I have the following:
Upload.upload({
url: 'upload',
data: {file: $scope.imagem}
}).progress(function (evt) {
}).success(function (data, status, headers, config) {
});
So far I have not been successful. Could someone help me?
EDIT
I tried using Postman to send a pro server image, but it gives the same exception as when I try to send it to my client: