'Change the size limits while doing export of byte array as CSV from Blazor Server
I am using following code to convert a byte[] to CSV file
@inject IJSRuntime JsRuntime
var fileBytes = //Helper method return the byte array back
var fileName = string.Format("FileExport_UUID_{0}.csv", DateTime.Now.ToString("u"));
await JsRuntime.InvokeAsync<object>("saveAsFile", fileName, Convert.ToBase64String(fileBytes));
The Javascript is like below
/**
* Export to excel helper method
* Inspired from project : blazorhero/CleanArchitecture wwwroot/js/file.js File
* File path : https://github.com/blazorhero/CleanArchitecture/blob/637517163f1e7f40b6be0952f8cf4ab690d759e0/src/Client/wwwroot/js/file.js
* @param {any} options
*/
window.saveAsFile = function (fileName, byteBase64) {
console.log("saveasFileCalled***");
var link = this.document.createElement('a');
link.download = fileName;
//link.href = "data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64," + byteBase64;
//link.href = "data:application/octet-stream;base64," + byteBase64;
link.href = "data:text/csv;base64," + byteBase64;
this.document.body.appendChild(link);
link.click();
this.document.body.removeChild(link);
console.log("End OF saveasFileCalled***");
}
The code is working fine for smaller byte arrays , however when the size of records is growing the export is not happening . Managed to download around 100 000 records, but when try to export a csv with 200 000 records, nothing is happening. On some machines export will work but on some other machines connected to slow network etc nothing is happening (After checking the file size from the machines where this export is completed I can see that size is around 90 MB )
While checking the Console I can see console.log("saveasFileCalled***"); & console.log("End OF saveasFileCalled***");
I am using .net 6 blazor Server side project Is any work arounds to reset the file size or any better way to do the job in .net 6
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
