1

Error: Spanish character is imported wrongly.

The text file contains Spanish and English characters.

*.txt

Jose Nuñez,David Gutiérrez,Rocío Moreno,César Millones .....

Output after import to the server

Jose Nuñez,David Gutiérrez,Rocío Moreno ....

*.ts

onFileChange(event: any) {
    const target: DataTransfer = <DataTransfer>(event.target);
    if (target.files.length !== 1) throw new Error('Cannot use multiple files');
    if (target.files.length !== 1 && event.target.accept !== ".txt") throw new Error('Cannot use multiple files');
    this.uploadedFileName = target.files[0].name;
    if (target.files.length == 1 && (target.files[0].type == ".txt" || target.files[0].type == "text/plain")) {
      this.uploadedFileName = event.target.files[0].name;
      if (event.target.files.length > 0) {
        const file = event.target.files[0];
        this.tFileList = event.target.files[0];
        this.searchFilterForm.get('edt').setValue(file);
      }
    }
    else {
      this.processErrorDetails = "Please select .txt file only!";
    }

  }

Service

public Import(body: any, observe: any = 'body', reportProgress: boolean = false): Observable < any > {
    let headers = this.defaultHeaders;

    headers.append('Content-Type', 'text/plain');

    return this.httpClient.post<any>(`${this.URL}/import_files`,
        body,
        {
            observe: 'response'
            , headers: headers

        }
    );

}
Murugan
  • 95
  • 2
  • 12
  • 1
    This is an encoding problem: you have two incompatible encodings. it seems the first is Latin1, and the second it is UTF-8 (very recommended for web, and all things, fonts now uses Unicode (UTF-8 or UTF-16) -- check with your text viewer/editor which encoding you are using, and maybe you can use it to convert to UTF-8) – Giacomo Catenazzi Dec 10 '20 at 08:11
  • Does this answer your question? [Angular 6: How to set response type as text while making http call](https://stackoverflow.com/questions/50798592/angular-6-how-to-set-response-type-as-text-while-making-http-call) – JosefZ Dec 10 '20 at 13:11

0 Answers0