html5 - Unable to download large data using javascript -


i have large data in form of json object in javascript. have converted string using json.stringify(). use case provide large string in text file user. have written below code.

html code

  <button id='text_feed' type="submit">generate ion feed</button>    <a href="data:attachment/txt" id="textlink" download="feed.txt"></a> 

javascript code

 var text = //huge string     $("#text_feed").click(function() {         _generatefeed(text);  });   var _generatefeed = function(text) {     //some code here     $("#textlink").attr("href",                           "data:attachment/txt," + encodeuricomponent(text))  [0].click();     });  };  

problem: when string length small , able download data . when string length goes higher (> 10^5) , page crashes. occurred because "encodeuricomponet(text)" not able encode large data.

i tried window.open("data:attachment/txt," + encodeuricomponent(text)); again page got crashed because of same reason encodeuricomponet unable encode such large string.

another approach: thinking of writing data file using html5 file write api , has support in chrome web browser , need make work atleast firefox , chrome both.

use case don't want multiple downloads breaking data, need have data in single file in end.

and target support string of aprroximately 10^6 length. can me how download/write amount of data single file.

from op:

i solved below.

var _generatefeed = function(text) {     /*some code here*/     var url = url.createobjecturl( new blob( [text], {type:'text/plain'} ) );     $("#textlink").attr("href",url)[0].click(); };  

notes:


Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -