Skip to content

Commit 391ab43

Browse files
author
Mayur
committed
fix: Added the Download sample file from Azure storage
1 parent 3596616 commit 391ab43

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

apps/widget/src/hooks/useSample.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useMutation } from '@tanstack/react-query';
44
import { variables } from '@config';
55
import { useAPIState } from '@store/api.context';
66
import { useAppState } from '@store/app.context';
7-
import { downloadFileFromURL, getFileNameFromUrl, notifier } from '@util';
7+
import { buildFullFileUrl, downloadFileFromURL, getFileNameFromUrl, notifier } from '@util';
88
import { ColumnTypesEnum, FileMimeTypesEnum, IErrorObject, ISchemaItem, ITemplate, downloadFile } from '@impler/shared';
99

1010
interface UseSampleProps {
@@ -20,7 +20,9 @@ export function useSample({ onDownloadComplete }: UseSampleProps) {
2020
[string, string]
2121
>(['getSignedUrl'], ([fileUrl]) => api.getSignedUrl(getFileNameFromUrl(fileUrl)), {
2222
onSuccess(signedUrl, queryVariables) {
23-
downloadFileFromURL(signedUrl, queryVariables[variables.firstIndex]);
23+
const fullFileUrl = buildFullFileUrl(signedUrl, queryVariables, variables.baseIndex);
24+
25+
downloadFileFromURL(fullFileUrl, queryVariables[variables.firstIndex]);
2426
},
2527
onError(error: IErrorObject) {
2628
notifier.showError({ title: error.error, message: error.message });

apps/widget/src/util/helpers/common.helpers.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ function fetchFile(urlToFetch: string, name: string) {
4848
});
4949
}
5050

51+
export function buildFullFileUrl(signedUrl: string, queryVariables: string[], baseIndex: number) {
52+
const filePath = queryVariables[baseIndex];
53+
const url = new URL(signedUrl);
54+
55+
return `${url.origin}${url.pathname}${filePath}${url.search}`;
56+
}
57+
5158
export function downloadFileFromURL(url: string, name: string) {
5259
if (!isValidHttpUrl(url)) return;
5360

0 commit comments

Comments
 (0)