Skip to content

fix: send headers for file download #355

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 6, 2025
Merged

Conversation

lyjeileen
Copy link
Collaborator

Changes

  • send headers for file download

Screenshots

May-05-2025 13-23-23

}

export default function DownloadButton(props: DownloadButtonProps) {
function handleAuthenticatedDownload() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would make the code easier to understand if a param is used for this method

Suggested change
function handleAuthenticatedDownload() {
function handleAuthenticatedDownload(getHeadersFn: GetAuthHeaders) {

Comment on lines 26 to 30
const link = document.createElement('a')
link.href = downloadUrl
link.download = props.fileName
document.body.appendChild(link)
link.click()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: use temporaryLink to make it obvious this will be deleted

Comment on lines 19 to 23
return fetch(props.url, { headers })
})
.then((response) => {
return response.blob()
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be simplified using axios

  // Use axios to fetch the file
      return axios.get(props.url, {
        headers,
        responseType: 'blob', // Important to specify 'blob' to handle file downloads
      });
    })
    .then((response) => {
      const blob = response.data

      // Create a download link and trigger the download
      const downloadUrl = URL.createObjectURL(blob)
     

@lyjeileen lyjeileen merged commit f1bc0da into rustic-ai:main May 6, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants