I want to export data as a Data URI, only if the size of the data doesn't exceed the max size of the Data URI supported by the current browser is bigger than the file I want to download.
document.location.href= "data:application/vnd.openxmlformats-officedocument.wordprocessingml.document;base64,"+data
This sometimes results in a Browser error when the file is too big, but I wish that the error could be catched before the download (to try an other method for example).
How can I get the max Data-URI size in JS ?
I have decided to hardcode this table:
Here's the script I use to test the maxsize:
String.prototype.repeat = function( num )
{
return new Array( num + 1 ).join( this );
}
testDataURI=function(size)
{
window.open("data:text/plain,"+"a".repeat(size-16))
}
testDataURI(100000) //test 100k characters
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With