angular - 打字稿检索 ArrayBuffer 的数组
问题描述
对不起,如果这已经被问到了,但我找不到任何东西。
我有一个在 Kotlin 中制作的后端的休息电话,在那里我得到了一个 ByteArray 列表。但我不知道如何在 Angular/TypeScript 中处理这个问题。在以前的版本中,我只有一个 ArrayBuffer,函数是这样的:
downloadDoc(correlationId: string): any {
const httpOptions = {
'responseType' : 'arraybuffer' as 'json'
};
return this.httpClient
.get<ArrayBuffer>('/rest/someUrl/' + correlationId, httpOptions)
.map(res => {
if(res.byteLength > 0) {
return new Blob([res], {type: "image/png"});
} else {
return new Blob(['Your document was not found'], {type: "text/plain"});
}
});
}
这仅适用于 ArrayBuffer,但不适用于 List。
我试过这个,但似乎没有渲染图像
downloadDoc(correlationId: string): Observable<Array<any>> {
return this.httpClient
.get<Array<any>>('/rest/someUrl/' + correlationId)
.map(results =>
results.map(result => new Blob([result], { type: "image/png" })
)
);
}
我想要做的是:
openDocument() {
this.pngService.downloadDoc(correlationId).subscribe(results => {
const tab = window.open("", '_blank');
let data = "";
results.forEach(function (value) {
const fileURL = URL.createObjectURL(value);
data = data.concat("<img src=\"" + fileURL +"\">")
});
tab.document.write(data);
});
}
但生成的 URL 已损坏,不会在新选项卡中加载任何图像。
解决方案
推荐阅读
- python - matplotlib - What am I doing wrong here?
- excel - 具有两个条件的 Instr 函数
- java - 如何限制 Firebase 电子邮件登录中的错误密码尝试?
- javascript - ES6 import multiple files
- ios - Constraints for two UIStackView - one under the other
- gremlin - Gremlin 查询以获取 k 距离顶点和连接它们的边
- node.js - 无法离线 npm 安装串行端口(或“node-gyp 重建”)
- reactjs - 类组件的 useEffect 替代品
- javascript - While fetching details using GET request, 401 error returns
- r - 有没有办法在 for 循环中动态使用已经创建的变量?