本文整理汇总了TypeScript中@angular/http.Response.blob方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Response.blob方法的具体用法?TypeScript Response.blob怎么用?TypeScript Response.blob使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@angular/http.Response
的用法示例。
在下文中一共展示了Response.blob方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: switch
return this.http.request(request).map( (response: Response) => {
let resp: any;
// handle response by expected responsetype
switch (request.responseType) {
case (ResponseContentType.Json):
resp = response.json();
break;
case (ResponseContentType.Text):
resp = response.text();
break;
case (ResponseContentType.Blob):
resp = response.blob();
break;
case (ResponseContentType.ArrayBuffer):
resp = response.arrayBuffer();
break;
default:
resp = response.json();
}
if (resp && resp.error) {
console.log("why are we here?");
}
return resp;
})
示例2: FileReader
conn.response.subscribe((res: ngResponse) => {
let reader: FileReader = new FileReader();
reader.addEventListener('loadend', function() {
expect(reader.result).toBe(RESPONSE_BODY);
done();
});
reader.readAsText(res.blob());
});
示例3: Blob
this.documentService.obtainReport(this.document).subscribe((res: Response) => {
const contentDisposition = res.headers.get('Content-Disposition');
let filename = this.document.documentId + '.pdf';
if (contentDisposition) {
filename = res.headers.get('Content-Disposition').match(/filename=(.*)/)[1];
}
const file = new Blob([res.blob()], { type: res.headers.get('Content-Type') });
saveAs(file, filename);
});
示例4:
.then((response: Response) => {
var contentType = response.headers.get("Content-Type");
if (contentType.startsWith("image/")) {
Urls.blobToDataUri(response.blob())
.then((dataUri: string) => {
this.data = dataUri;
this.load.emit(this.data);
});
}
},
示例5: extractContent
/**
* Extract the File from Response context and download it
* @param res Response
*/
private static extractContent(res: Response, viewImage: boolean) {
let blob: Blob = res.blob();
let mainHead = res.headers.get('content-disposition');
let filename = mainHead.split(';')
.map(x => x.trim())
.map(
s => {
if (s.split('=')[0] === 'filename') {
return s.split('=')[1];
}
}
).filter(x => x)[0];
let url = window.URL.createObjectURL(blob);
if (viewImage) {
return blob;
} else {
let a = document.createElement('a');
a.href = url;
a.download = typeof(filename) === 'string' ? filename : 'download';
a.target = '_blank';
a.click();
a.remove();
}
}