decoded
September 18, 2018, 2:36pm
1
I am trying to get image data via user file ulpoad - from JavaScript into Defold using html5_run()
There seems to be a limit(around 2048) for data that is passed back on return .
Is this correct, or is something else going on?
For example, in Defold I use this:
local result = html5.run("upload_file();")
Which gets the image source through JavaScript:
<script type='text/javascript'>
function upload_file() {
var output = document.getElementById('output_image');
return output.src;
};
</script>
And gives me something like this (for a very small icon):
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAYAAADED76LAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEwAACxMBAJqcGAAAAC5JREFUGJVjZEAF/xlIBP+ZsAguYGBg4EI3Fh2vwmflfCQTCLrpPyO6ACEdGAAANaMM9wuhrTQAAAAASUVORK5CYII=
For larger images, the data gets truncated and corrupts the image.
No I don’t see that our code does any limitation per se. We use emscripten_run_script_string
though, but that too seems to be dynamic (source )
What if you print the content+length in the upload_file()
function, just after the “var output = …” statement, does it look ok then?
1 Like
decoded
September 18, 2018, 7:22pm
3
I think “upload file” probably confuses this a little. I’m technically trying to avoid actual uploading - but not sure if this will work.
There’s definitely some kind of limit in return from JavaScript with length > 2048 to html5_run()
Edit:
Repro case added below
Hmm, strange. Perhaps you can create a small repro case and I can take a look at it tomorrow?
2 Likes
decoded
September 18, 2018, 10:34pm
5
Yes of course. Happy to have you take a look if you don’t mind.
Here’s a Defold project that reproduces the issue. decoded-html5-overflow.zip (4.2 KB)
(Build HTML5 and inspect console)
2034 seems to be the magic number, not 2048.
The repro case uses html5.run() with these:
<script type='text/javascript'>
function get_data_overflow() {
return (Array(2034).join('x'));
};
function get_data_ok() {
return (Array(2033).join('x'));
};
</script>
decoded
September 19, 2018, 4:10am
6
It’s OK to tell me, “just don’t use really long strings stupid!”
They seem to break a lot of things…
print() is apparently limited , and sometimes will not output if string length is too long.
Could be why this is happening.
The Defold editor itself will throw “java.lang.StackOverflowError: Unknown” if you type enough text in one line.
I think
there is an issue for that already.
please don’t worry too much about this.
I believe the solution is for me to find a way that avoids long string data.
Well, it seems it was just the print that doesn’t support too long strings.
I changed the function like so:
function get_data_overflow() {
var prefix = Array(8).join('a')
var suffix = Array(8).join('b')
var s = prefix + Array(4096).join('x') + suffix;
console.log("LENGTH is " + s.length);
return s;
};
And the printout like so:
print(string.sub(result, 0, 16), "...", string.sub(result, #result-15))
And I get:
LENGTH is 4109 // from javascript
DEBUG:SCRIPT: data is TOO BIG. len is 4109
DEBUG:SCRIPT: aaaaaaaxxxxxxxxx ... xxxxxxxxxbbbbbbb
2 Likes
decoded
September 19, 2018, 11:47pm
8
Thanks a ton @Mathias_Westerdahl - you inadvertently helped me with another question also.
How to strip the image headers from the base64 encoding.
All that fancy string manipulation, and no limits in the html5.run() return - it works!
4 Likes