I am getting this string response from a REST API call. It is a file but it's in string. I am stuck on how to convert it into the readable stream so I can save it into the system.
This might not be what you want, but I believe it answers the second part of your question:
It could be different depending on which HTTP client you are using, but if you use the node http or https module, then the response will be a readable stream by default.
发布评论
评论(3)
使用node-fetch解决了这个问题,并在response.body()上它返回一个可读流。
Solved it using node-fetch and on response.body() it's returning a readable stream.
基于 EXIF 和 XMP 数据,您正在查看图像。
您无法将其作为(人类可读文本)字符串进行处理,因此没有可使用的“编码”。只需将其存储为二进制即可。
Based on the presence of EXIF and XMP data, you're looking at an image.
You can't process it as a (human-readable-text) string, so there is no "encoding" to work with. Just store it as binary.
这可能不是您想要的,但我相信它回答了您问题的第二部分:
根据您使用的 HTTP 客户端,它可能会有所不同,但如果您使用 节点 http 或 https 模块,则默认情况下响应将是可读流。
This might not be what you want, but I believe it answers the second part of your question:
It could be different depending on which HTTP client you are using, but if you use the node http or https module, then the response will be a readable stream by default.