Skip to content

Commit

Permalink
Merge pull request #1111 from PintoGideon/prototype-downloads
Browse files Browse the repository at this point in the history
bug: Query Param's don't work
  • Loading branch information
PintoGideon authored Mar 13, 2024
2 parents 359385c + 49a0b6d commit 6bffd0e
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/components/FeedOutputBrowser/FileBrowser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,27 @@ const FileBrowser = (props: FileBrowserProps) => {
if (item) {
try {
const fileName = getFileName(item.data.fname);
const url = item.data.url;
const url = item.url;
const client = ChrisAPIClient.getClient();
const token = client.auth.token;
const authorizedUrl = `${url}${fileName}?token=${token}`; // Add token as a query parameter
const requestUrl = `${url}${fileName}`;

const response = await fetch(requestUrl, {
headers: {
Authorization: `Token ${token}`, // Added a space after Token
},
});

if (!response.ok) {
throw new Error(
`Failed to download file. Status: ${response.status}`,
);
}

const blob = await response.blob(); // Corrected this line

const link = document.createElement("a");
link.href = authorizedUrl;
link.href = window.URL.createObjectURL(blob);
link.download = fileName;
document.body.appendChild(link);
link.click();
Expand Down

0 comments on commit 6bffd0e

Please sign in to comment.