File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -5,8 +5,26 @@ export const getResponseBody = async (response: Response): Promise<any> => {
5
5
if (contentType) {
6
6
const jsonTypes = ['application/json', 'application/problem+json']
7
7
const isJSON = jsonTypes.some(type => contentType.toLowerCase().startsWith(type));
8
+ const isBlob = contentType.toLowerCase().startsWith('image/')
9
+ || contentType.toLowerCase().startsWith('application/pdf')
10
+ || contentType.toLowerCase().startsWith('application/zip')
11
+ || contentType.toLowerCase().startsWith('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
12
+ || contentType.toLowerCase().startsWith('application/octet-stream');
13
+
8
14
if (isJSON) {
9
15
return await response.json();
16
+ } else if (isBlob) {
17
+ const blob = await response.blob();
18
+ const disposition = response.headers.get('Content-Disposition');
19
+ if (disposition && disposition.indexOf('attachment') !== -1) {
20
+ const filenameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/;
21
+ const matches = filenameRegex.exec(disposition);
22
+ if (matches !== null && matches[1]) {
23
+ const filename = decodeURIComponent(matches[1].replace(/['"]/g, ''));
24
+ return new File([blob],filename,{ type: contentType })
25
+ }
26
+ }
27
+ return blob;
10
28
} else {
11
29
return await response.text();
12
30
}
You can’t perform that action at this time.
0 commit comments