解析图像时 Angular 5 HTTP 失败

标签 angular image http parsing express

我想使用 Angular 使用其文件名从 Express 服务器获取图像:

Request from Angular service

我想将文件发送回客户端:

Sending file from Express server

当我记录来自服务器的响应时,出现以下错误:

Error message from response

我几乎可以肯定我在请求或响应中遗漏了任何选项,但我不确定是什么。

如有任何帮助,我们将不胜感激。

最佳答案

HttpClient 将“json()”方法应用于响应,因此如果您的响应是非 JSON 数据,您将遇到此类错误。

虽然这是最常见的,但有时您会处理不同类型的数据。这是通过 responseType 属性支持的。

this.http.get('...', { responseType: 'text' }); //

responseType?: 'arraybuffer' | 'blob' | 'json' | 'text'

关于解析图像时 Angular 5 HTTP 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51410062/

相关文章:

angular - 设置 Angular Material 的值以编程方式选择自动完成

javascript - 动态组件列表上带有 ng-template 的 cdkDropList 不起作用

python - 尝试使用 kairos 上传文件时出错

java - 为什么我的 JFrame 图像没有更改图标?

html - 将可缩放图像定位在其他图像之上

angular - 有没有办法将 Angular 数据表与每列 "angular way"的过滤器一起使用?

angular - "Cannot return null for non-nullable field"使用 Graphql 订阅 NestJS 时

javascript - 谁真正在 Web 浏览器中执行 HTTP 请求?

http - Netty 中 HttpMessageDecoder.skipControlCharacters 上的 NullPointerException

javascript - $http 响应和 Api 响应的区别 [AngularJs]