我正在使用角度从本地存储访问文本文件,它是一个 base64 编码的文本文件。当我收到 http 响应时,它会返回一个错误

问题描述 投票:0回答:0
error: SyntaxError: Unexpected token '/', "/9j/4AAQSk"... is not valid JSON at JSON.parse (<anonymous>) at XMLHttpRequest.onLoad (http://localhost:4200/vendor.js:147467:51)

message: "Unexpected token '/', \"/9j/4AAQSk\"... is not valid JSON"

文本文件包含图像的 base64 编码字符串。我在服务中的作用:

getFileContent() {
      return this.http.get('http://localhost:3001/genPK-main-service/api/v1/files?filePath=C:/media/images/33599341.txt', { responseType: 'blob' });
    }

课堂功能:

this.imageService.getFileContent().subscribe(
        (data) => {
          this.fileContent = data;
          console.log(this.fileContent);
        },
        (error) => {
          console.error(error);
        }
      );

另外,我用过

{ responseType: 'text' }

在 http.get 服务中但没有任何反应:(

json angular base64 httpclient
© www.soinside.com 2019 - 2024. All rights reserved.