-
Notifications
You must be signed in to change notification settings - Fork 5k
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
Avoid blob url for files downloads #17986
Avoid blob url for files downloads #17986
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #17986 +/- ##
========================================
Coverage 63.44% 63.44%
========================================
Files 903 903
Lines 35267 35263 -4
Branches 8920 8918 -2
========================================
- Hits 22373 22371 -2
+ Misses 12894 12892 -2
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
@@ -1,19 +1,23 @@ | |||
import { getRandomFileName } from './util'; | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prefer async over callbacks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ui/helpers/utils/export-utils.js
Outdated
const elem = window.document.createElement('a'); | ||
elem.target = '_blank'; | ||
elem.href = window.URL.createObjectURL(blob); | ||
elem.href = `data:${type};Base64,${b64}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we just use btoa
? https://developer.mozilla.org/en-US/docs/Web/API/btoa
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unfortunately btoa
fails on special chars that we have in the exported json files that TextEncoder
successfully deals with (I learned the hard way)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
interesting -- what about Buffer.from(xyz, 'utf8').toString('base64')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ui/helpers/utils/export-utils.js
Outdated
@@ -1,19 +1,13 @@ | |||
import { getRandomFileName } from './util'; | |||
|
|||
export function exportAsFile(filename, data, type = 'text/csv') { | |||
export async function exportAsFile(filename, data, type = 'text/csv') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no longer needs to be async
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exportAsFile
exportAsFile
creates a URL object from a Blob and downloads that (common trick)exportAsFile
function, which will achieve the exact same goal but without the dangerous combo, but rather withdata:
URI instead