javascript - Browser crashes while downloading large size files -


i have web api reads file azure , downloads byte array. client receives byte array , downloads pdf. not work large files. not able figure out how can send bytes in chunks web api client.

below web api code returns byte array client:

        cloudblockblob blockblob = container.getblockblobreference(filename);         blockblob.fetchattributes();         byte[] data = new byte[blockblob.properties.length];         blockblob.downloadtobytearray(data, 0);         return report; 

client side code gets data when ajax request completes, creates hyperlink , set download attribute downloads file:

var = document.createelement("a"); a.href = 'data:application/pdf;base64,' + data.$value;; a.setattribute("download", filename); 

the error occurred file of 1.86 mb.

the browser displays message: went wrong while displaying web page.to continue, reload webpage.

the issue server running out of memory on these large files. don't load entire file variable send out response. causes double download, server has download azure storage , keep in memory, client has download server. can stream stream copy instead memory not chewed up. here example webapi controller.

public async task<httpresponsemessage> getpdf() {     //normally using statement streams, if use 1 here, stream closed before client downloads it.      stream stream;     try     {         //container setup earlier in code          var blockblob = container.getblockblobreference(filename);          stream = await blockblob.openreadasync();          //set response stream content azure storage         response.content = new streamcontent(stream);         response.content.headers.contentlength = stream.length;          //this change based on file type         response.content.headers.contenttype = new mediatypeheadervalue("application/pdf");     }     catch (httpexception ex)     {         //a network error between server , azure storage         return this.request.createerrorresponse((httpstatuscode)ex.gethttpcode(), ex.message);     }     catch (storageexception ex)     {         //an azure storage exception         return this.request.createerrorresponse((httpstatuscode)ex.requestinformation.httpstatuscode, "error getting requested file.");     }     catch (exception ex)     {         //catch exception...log this, don't bleed exception client         return this.request.createerrorresponse(httpstatuscode.badrequest, "bad request");     }         {         stream = null;     } } 

i have used (almost exactly) code , have been able download files on 1gb in size.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -