本文整理匯總了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();
}
}