I have a project with Spring boot and I'm trying to upload a csv file which contains special character i.e: "ΕΛΙΑ ΚΑΤΑΣΚΕΥΑΣΤΙΚΗ Α.Ε.", while processing file special character getting replaced by following "???? ?????????????? ?.?."
Controller
@RequestMapping(value = "/processfile", method = RequestMethod.POST)
public void processMultiPartFile(HttpServletRequest request, @RequestParam("files") MultipartFile[] files) {
for (MultipartFile file : files) {
System.out.println("File data-->>"+new String(file.getBytes(),"UTF-8"))
}
}
Attempted the following solutions but no success so far :
Solution 1: set character encoding in request
request.setCharacterEncoding("UTF-8");
Solution 2: use inputstreamreader of mutipartfile
BufferedReader in = new BufferedReader(new InputStreamReader(file.getInputStream(), "UTF-8"));
String line = null;
while((line = in.readLine()) != null) {
System.out.println("read data----->"+line);
}
Solution 3: try with CommonsMultipartResolver
exclude auto configuration by
@EnableAutoConfiguration(exclude = {MultipartAutoConfiguration.class})
and add custom resolver
@Bean(name="multipartResolver")
public CommonsMultipartResolver multipartResolver(){
CommonsMultipartResolver resolver = new CommonsMultipartResolver();
resolver.setDefaultEncoding("UTF-8");
return resolver;
}
and add the following dependency in pom.xml
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.4</version>
</dependency>
Application environment
- Platform 1: Windows 7, deployment and running on console (for local debugging)
- Platform 2: Google Cloud, deployment and running on AppEngine.
Note: While running application in eclispse(Luna) IDE on local system, getting correct output in console.