java - Large file does not download with jsp -


i sending ajax post request script inside jsp.

inside controller reading file location , return byte array.

fileinputstreamreader = new fileinputstream(file);         byte[] bytes = new byte[(int) file.length()];         fileinputstreamreader.read(bytes);          filedata = base64.getencoder().encode(bytes);         response.setheader("content-disposition", "attachment; filename=" + filename);         response.setcontentlength((int) file.length());         fileinputstreamreader.close(); 

then on front end crating invisible link , downloading file.

$.ajax({     url : url,     type : 'post',     data : nodedata,     beforesend : function(jqxhr, settings) {         setcsrfheader(jqxhr);     },     success : function(data) {          hideloader();        /* window.open("data:"+contenttype+";base64, " + data); */         var uri = 'data:'+contenttype+';base64,' + data;         var downloadlink = document.createelement("a");         downloadlink.href = uri;         downloadlink.download =atcname ;          document.body.appendchild(downloadlink);         downloadlink.click();         $("#success").html("file download successful");         $("#error").hide();         $("#success").show();         document.body.removechild(downloadlink);      },     error : function(e) {          hideloader();          $("#error").html(error_server_response);          $("#success").hide();          $("#error").show();         alert(error_server_response);     } });  

the problem large file size >~50mb. should do?

i might wrong suggest check if there no cache issue because timeout should trigger error callback.

you should add aparameter cache : false, in request or, better imho, can prevent futher ajaxs call being cached, regardless of jquery method use(ajax, get...).

$.ajaxsetup({ cache: false }); 

Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -