-
Notifications
You must be signed in to change notification settings - Fork 209
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
Convert url to blob for large file size download #1455
Conversation
Codecov Report
@@ Coverage Diff @@
## main #1455 +/- ##
==========================================
- Coverage 66.67% 64.73% -1.95%
==========================================
Files 130 127 -3
Lines 2686 2603 -83
Branches 433 418 -15
==========================================
- Hits 1791 1685 -106
- Misses 895 918 +23
|
@publiclab/is-reviewers |
Previously files around 1 mb or greater were not possible but this PR makes it possible to download large files |
Works fine! Since this project is in ES6, why don't you use |
@LeoDog896 Done |
This one is outdated. Closing for now, please feel free to rebase and reopen :) |
Hi @harshkhandeparkar i wonder if this would help performance on larger images, and it looks like a relatively complete PR. Should we test it out and consider merging it? |
element.setAttribute('download', step.name + '.' + fileExtension(step.imgElement.src)); | ||
element.style.display = 'none'; | ||
document.body.appendChild(element); | ||
var blob = dataURLtoBlob(step.output); | ||
var objurl = URL.createObjectURL(blob); |
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.
What is the difference between this URL and dataURL?
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.
I just encountered this in https://github.com/jywarren/bookletize.js and data urls have a length limit in browsers, so they fail on large files, and also blob is more efficient because they don't need to be reencoded.
I think this is probably worth it!
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 internally use blobs too, then?
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.
I think it's possible. We had very very long ago considered different formats for between-module data handoff, including possibly buffers...? i forget, but it was in our very first issue: #1 (comment)
We could open a new issue with this idea -- basically that default is data-urls, because strings are completely compatible, but if two modules can negotiate that both are compatible with blobs, that's OK too. I think the data-urls worked especially well because they had to be displayed anyways. But now that I think of it I think it's possible to display a blob as well in the browser. Please feel free to open an issue to discuss this!
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.
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.
I wonder if this would just work, but it depends on the run environment, I imagine:
Lines 18 to 54 in 5298d1e
var i = drawarray[pos].i; | |
var input = ref.steps[i - 1].output; | |
var step = ref.steps[i]; | |
step.getStep = function getStep(offset) { | |
if (i + offset >= ref.steps.length) return { options: { name: undefined } }; | |
else return ref.steps.slice(i + offset)[0]; | |
}; | |
step.getIndex = function getIndex() { | |
return i; | |
}; | |
for (var util in getStepUtils) { | |
if (getStepUtils.hasOwnProperty(util)) { | |
step[util] = getStepUtils[util]; | |
} | |
} | |
// Tell UI that a step is being drawn. | |
step.UI.onDraw(step.options.step); | |
// provides a set of standard tools for each step | |
var inputForNextStep = require('./RunToolkit')(ref.copy(input)); | |
step.draw( | |
inputForNextStep, | |
function onEachStep() { | |
// This output is accessible by UI | |
ref.steps[i].options.step.output = ref.steps[i].output.src; | |
ref.steps[i].options.step.wasmSuccess = ref.steps[i].output.wasmSuccess || false; | |
ref.steps[i].options.step.useWasm = ref.steps[i].output.useWasm || false; | |
// Tell UI that step has been drawn. | |
ref.steps[i].UI.onComplete(ref.steps[i].options.step); | |
drawStep(drawarray, ++pos); |
We could add a parameter to drawStep somewhere that evaluates whether the neighboring steps can both handle blobs.
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.
I broke this into an issue at #1847 !!
Merging this! 🎉 at last, thank youuuuuuu!!! |
Fixes #1429 (<=== Replace
0000
with the Issue Number)Make sure these boxes are checked before your pull request (PR) is ready to be reviewed and merged. Thanks!
npm test
@publiclab/is-reviewers
for help, in a comment belowIf tests do fail, click on the red
X
to learn why by reading the logs.Please be sure you've reviewed our contribution guidelines at https://publiclab.org/contributing-to-public-lab-software
Please make sure to get at least two reviews before asking for merging the PR as that would make the PR more reliable on our part
Thanks!