1

i am start learn JS, my server give me file with encoding windows-1251

 return ResponseEntity
                .ok()
                .contentType(MediaType.parseMediaType(determinateContentType(request, res)))
                .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + res.getFilename() + "\"")
                .body(res); 
@NotNull
    private String determinateContentType(@NotNull HttpServletRequest request, @NotNull Resource resource) {
        String contentType;
        try {
            String absolutePath = resource.getFile().getAbsolutePath();
            contentType = request.getServletContext().getMimeType(absolutePath);
        } catch (IOException e) {
            log.error("Wrong file URL", e);

            throw new NotFoundException("Wrong file URL", e.getCause());
        }

        if (contentType == null) {
            contentType = "application/octet-stream";
        }

        return contentType;
    } 

if i download file with Postman- all good,but i add button :

async downloadValidationReport(): Promise<void> {
   const result = await http.post<string>(await getExportValidationResultUrl(), this.preparePayload(), {
     headers: { 'Content-Type': 'application/json' }
   });
   const file = new Blob([result], { type: 'text/csv' });
   saveAs(file, 'validation.csv');
 } 

And this is problem: file come in with hieroglyphs like this: Çîíà çàñòðîéêè èíäèâèäóàëüíûìè æèëûìè äîìàìè" I need help, what can I do? Where does the encoding change take place? I will be grateful for your help

framzik
  • 27
  • 3

1 Answers1

0

Thanks this answer i do what i am need(encoding do not change to windows-1251, but Excel open correctly)

framzik
  • 27
  • 3