Using Javascript's atob to decode base64 doesn't properly decode utf-8 strings

后端 未结 10 2123
野趣味
野趣味 2020-11-22 16:24

I\'m using the Javascript window.atob() function to decode a base64-encoded string (specifically the base64-encoded content from the GitHub API). Problem is I\'

10条回答
  •  梦谈多话
    2020-11-22 16:33

    including above solution if still facing issue try as below, Considerign the case where escape is not supported for TS.

    blob = new Blob(["\ufeff", csv_content]); // this will make symbols to appears in excel 
    

    for csv_content you can try like below.

    function b64DecodeUnicode(str: any) {        
            return decodeURIComponent(atob(str).split('').map((c: any) => {
                return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
            }).join(''));
        }
    

提交回复
热议问题