0

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.

Ankit.A
  • 1
  • 2
  • [1] Try adding this call to `System.setOut()` before making calls to `println()`: `System.setOut(new PrintStream(System.out, true, "UTF8"));` [2] What platform are you running on? Windows? [3] How are you running your app? From the console? Within the IDE? – skomisa Mar 07 '19 at 04:39
  • @skomisa still getting the same issue. For environment details, updated the question. – Ankit.A Mar 07 '19 at 05:22
  • OK. When running your app from the Console in Windows you need to change your code page to support UTF-8, so call `chcp 65001` in the Console window before running your app. Does that change anything? – skomisa Mar 07 '19 at 05:32
  • After run [chcp 65001] : get following output [Active code page: 65001], but still getting same issue. – Ankit.A Mar 07 '19 at 05:45

0 Answers0