так выглядит двоичный файл.
Вот как я подписываюсь на метод, который извлекает файл pdf blob
public downloadDoc(token: any, docNumber: number) {
this.loading = true;
this._docService.getDocumentStreams(token, docNumber).subscribe(res => {
this.loading = false;
let file = new Blob([res._body], {
type: 'application/pdf'
});
var fileURL = URL.createObjectURL(file);
console.info(res)
window.open(fileURL);
}, (error => {
console.info(`failed to download document: ${error}`);
}))
}
вот метод в службе
public getDocumentStreams(token: any, docNumber: number): Observable < any > {
const body = {
'DocNo': docNumber,
'StreamNo': 0
};
const headers = new Headers();
headers.append('Content-Type', 'application/json');
headers.append('Accept', 'application/json');
headers.append('TenantName', 'idl');
headers.append('UseToken', '1');
headers.append('Authorization', 'Basic ' + window.btoa('webapi' + ':' + token));
headers.append('responseType', 'arraybuffer'
as 'json');
return this.http.post(`${this._therefore_apiBase}/GetDocumentStreamRaw`, body, {
headers: headers
}).pipe(
map((response) => {
return response;
}));
}
Это распечатает бредовый файл pdf, в чем может быть проблема
Да, у меня есть. не сработало
Вы пытались изменить свой responseType в заголовке запроса на application / pdf вместо arraybuffer