How to display illegal characters on downloaded file name in Spring?

Iriskul Turduev :

My downloaded file name becomes Ça_r_lar_02_07_2019_12_09.xlsx, however, I want it Çağrılar_02_07_2019_12_09.xlsx. How Can I fix it?

try (Workbook workbook = new XSSFWorkbook()) {
                new XlsExporter().exportXls(workbook, grh);
                SimpleDateFormat sdf = new SimpleDateFormat("_dd_MM_yyyy_HH_mm");
                String name = grh.getReportName() + sdf.format(new Date());
                response.setContentType(MediaType.APPLICATION_OCTET_STREAM.getType());
                response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + name +  ".xlsx\"");
                workbook.write(response.getOutputStream());
                response.getOutputStream().flush();
            }
Alex :

Try UTF-8 encoding for your filename before sending the response

try (Workbook workbook = new XSSFWorkbook()) {
                new XlsExporter().exportXls(workbook, grh);
                SimpleDateFormat sdf = new SimpleDateFormat("_dd_MM_yyyy_HH_mm");
                String name = grh.getReportName() + sdf.format(new Date());
                name = URLEncoder.encode(name,"UTF-8"); 
                response.setContentType(MediaType.APPLICATION_OCTET_STREAM.getType());
                response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + name +  ".xlsx\"");
                workbook.write(response.getOutputStream());
                response.getOutputStream().flush();
            }

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=123172&siteId=1
Recommended