我在Angular 5中工作,将flatbuffers响应与我的API调用集成在一起。 我试图在Angular 5中使用HttpClient加载二进制文件。
我尝试过以下代码来获取Uint8Array中的字节数据。也尝试使用Blob,但它不起作用。
let apiUrl = "./assets/test.bin";
const headers = {
headers: new HttpHeaders({responseType: "application/octet-stream"})
};
let data : Observable<Uint8Array> = this.http.get<Uint8Array>(apiUrl, headers);
data.subscribe( (response: Uint8Array) => {
const data = response;
// console.log(data);
console.log("successful");
return data;
}, (error : HttpErrorResponse)=> {
console.log(error.error.text);
});
答案 0 :(得分:0)
尝试类似:
let apiUrl = "./assets/test.bin";
const headers = {responseType: "blob"};
let data : Observable<Blob> = this.http.get<Blob>(apiUrl, headers);
data.subscribe( (response: Blob) => {
const data = response;
console.log(data);
}, (error : HttpErrorResponse)=> {
console.log(error.error.text);
});