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 服务中但没有任何反应:(