0

I am new to Angular JS but I have good experience in Spring MVC. So, now I have the requirement where I need to upload a file. But, here I need to develop UI screen for uploading excel sheet using AngulaJS and backend will be Spring controller. Can anyone provide example for the same.

1 Answer 1

1

In Spring, this would be the method to accept multipart file uploads. myFile will contain all information of the uploaded file you need.

@RequestMapping(value = "{userId}/profile/image", method =   RequestMethod.POST)
public ResponseEntity<String> uploadProfileImage(@PathVariable String userId, @RequestParam("file") MultipartFile myFile) {
  ...

}

You might want to add the following Spring Bean to your setup, as well:

@Bean
public CommonsMultipartResolver multipartResolver() {
    CommonsMultipartResolver resolver = new CommonsMultipartResolver();
    resolver.setResolveLazily(false);
    resolver.setDefaultEncoding("utf-8");
    return resolver;
}

In Angular, there are several projects that allow for file uploads.

Angular1: https://github.com/nervgh/angular-file-upload

Angular2: https://github.com/valor-software/ng2-file-upload/tree/master/demo

Both easy to use with demos and samples on their github page.

Sign up to request clarification or add additional context in comments.

1 Comment

In some cases you might have specific requirements for the resolution of multipart requests. For instance, we had some issues with encodings (default is ISO-8859-1 according to the servlet spec, not utf8).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.