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> => {
55 if (contentType) {
66 const jsonTypes = ['application/json', 'application/problem+json']
77 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+
814 if (isJSON) {
915 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;
1028 } else {
1129 return await response.text();
1230 }
You can’t perform that action at this time.
0 commit comments