{"id":13807757,"url":"https://github.com/arivera12/BlazorDownloadFile","last_synced_at":"2025-05-14T00:32:03.138Z","repository":{"id":41888277,"uuid":"253332739","full_name":"arivera12/BlazorDownloadFile","owner":"arivera12","description":"Blazor download files to the browser from c# without any javascript library reference or dependency.","archived":false,"fork":false,"pushed_at":"2023-12-14T08:28:11.000Z","size":6244,"stargazers_count":189,"open_issues_count":12,"forks_count":27,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-12T21:32:05.604Z","etag":null,"topics":["blazor","blazordownloadfile","csharp"],"latest_commit_sha":null,"homepage":"","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/arivera12.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2020-04-05T21:10:07.000Z","updated_at":"2025-04-09T13:57:03.000Z","dependencies_parsed_at":"2024-04-10T02:56:06.156Z","dependency_job_id":"aa88e853-6743-488f-bfd5-679435d2d249","html_url":"https://github.com/arivera12/BlazorDownloadFile","commit_stats":{"total_commits":100,"total_committers":7,"mean_commits":"14.285714285714286","dds":"0.43999999999999995","last_synced_commit":"5d8976c60439fed3f016ea97674df697f3f8baa5"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arivera12%2FBlazorDownloadFile","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arivera12%2FBlazorDownloadFile/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arivera12%2FBlazorDownloadFile/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arivera12%2FBlazorDownloadFile/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arivera12","download_url":"https://codeload.github.com/arivera12/BlazorDownloadFile/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254046395,"owners_count":22005584,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["blazor","blazordownloadfile","csharp"],"created_at":"2024-08-04T01:01:30.000Z","updated_at":"2025-05-14T00:31:58.126Z","avatar_url":"https://github.com/arivera12.png","language":"HTML","funding_links":["https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick\u0026hosted_button_id=RSE2NMEG3F7QU\u0026source=url"],"categories":["Libraries \u0026 Extensions"],"sub_categories":["2D/3D Rendering engines"],"readme":"# BlazorDownloadFile\n\n\u003cp\u003e\n\t\u003ca href=\"https://www.nuget.org/packages/BlazorDownloadFile\"\u003e\n\t    \u003cimg src=\"https://buildstats.info/nuget/BlazorDownloadFile?v=2.4.0.2\" /\u003e\n\t\u003c/a\u003e\n\t\u003c!--\u003ca href=\"https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick\u0026hosted_button_id=RSE2NMEG3F7QU\u0026source=url\"\u003e\n\t    \u003cimg src=\"https://img.shields.io/badge/Donate-PayPal-green.svg\" /\u003e\n\t\u003c/a\u003e--\u003e\n\u003c/p\u003e\n\n![](BlazorDownloadFileDemo.gif)\n\nBlazor download files to the browser from c# without any JavaScript library or dependency.\n\nBlazorDownloadFile is the solution to saving files on the client-side, and is perfect for web apps that generates files on the client. \n\nHowever if the file is coming from the server we recommend you to first try to use Content-Disposition attachment response header as it has more cross-browser compatibility.\n\n## Installation\n\n`Install-Package BlazorDownloadFile -Version 2.4.0.2`\n\n## Register the service in your services method\n\n`services.AddBlazorDownloadFile(ServiceLifetime lifetime = ServiceLifetime.Scoped);`\n\nNote: `ServiceLifetime.Singleton` is not supported.\n\n## No javascript library reference dependency unless...\n\n## If you are using Content-Security-Policy \"script-src 'self'\" then you need to add the script manually: \n\n### \u003cscript src=\"_content/BlazorDownloadFile/BlazorDownloadFileScript.js\"\u003e\u003cscript\u003e\n\n## Usage\n\n`[Inject] IBlazorDownloadFileService BlazorDownloadFileService { get; set; }`\n\n### BlazorDownloadFileService Methods\n\n```\n/// \u003csummary\u003e\n/// Adds a buffer to javascript side\n/// \u003c/summary\u003e\n/// \u003cparam name=\"bytesBase64\"\u003eThe base 64 string\u003c/param\u003e\n/// \u003creturns\u003e\u003c/returns\u003e\nValueTask AddBuffer(string bytesBase64);\n/// \u003csummary\u003e\n/// Adds a buffer to javascript side\n/// \u003c/summary\u003e\n/// \u003cparam name=\"bytesBase64\"\u003eThe base 64 string\u003c/param\u003e\n/// \u003cparam name=\"cancellationToken\"\u003eThe cancellation token\u003c/param\u003e\n/// \u003creturns\u003e\u003c/returns\u003e\nValueTask AddBuffer(string bytesBase64, CancellationToken cancellationToken);\n/// \u003csummary\u003e\n/// Adds a buffer to javascript side\n/// \u003c/summary\u003e\n/// \u003cparam name=\"bytesBase64\"\u003eThe base 64 string\u003c/param\u003e\n/// \u003cparam name=\"timeOut\"\u003eThe timeout\u003c/param\u003e\n/// \u003creturns\u003e\u003c/returns\u003e\nValueTask AddBuffer(string bytesBase64, TimeSpan timeOut);\n/// \u003csummary\u003e\n/// Adds a buffer to javascript side\n/// \u003c/summary\u003e\n/// \u003cparam name=\"bytes\"\u003eThe bytes\u003c/param\u003e\n/// \u003creturns\u003e\u003c/returns\u003e\nValueTask AddBuffer(byte[] bytes);\n/// \u003csummary\u003e\n/// Adds a buffer to javascript side\n/// \u003c/summary\u003e\n/// \u003cparam name=\"bytes\"\u003eThe bytes\u003c/param\u003e\n/// \u003cparam name=\"cancellationToken\"\u003eThe cancellation token\u003c/param\u003e\n/// \u003creturns\u003e\u003c/returns\u003e\nValueTask AddBuffer(byte[] bytes, CancellationToken cancellationToken);\n/// \u003csummary\u003e\n/// Adds a buffer to javascript side\n/// \u003c/summary\u003e\n/// \u003cparam name=\"bytes\"\u003eThe bytes\u003c/param\u003e\n/// \u003cparam name=\"timeOut\"\u003eThe timeout\u003c/param\u003e\n/// \u003creturns\u003e\u003c/returns\u003e\nValueTask AddBuffer(byte[] bytes, TimeSpan timeOut);\n/// \u003csummary\u003e\n/// Adds a buffer to javascript side\n/// \u003c/summary\u003e\n/// \u003cparam name=\"bytes\"\u003eThe bytes\u003c/param\u003e\n/// \u003creturns\u003e\u003c/returns\u003e\nValueTask AddBuffer(IEnumerable\u003cbyte\u003e bytes);\n/// \u003csummary\u003e\n/// Adds a buffer to javascript side\n/// \u003c/summary\u003e\n/// \u003cparam name=\"bytes\"\u003eThe bytes\u003c/param\u003e\n/// \u003cparam name=\"cancellationToken\"\u003eThe cancellation token\u003c/param\u003e\n/// \u003creturns\u003e\u003c/returns\u003e\nValueTask AddBuffer(IEnumerable\u003cbyte\u003e bytes, CancellationToken cancellationToken);\n/// \u003csummary\u003e\n/// Adds a buffer to javascript side\n/// \u003c/summary\u003e\n/// \u003cparam name=\"bytes\"\u003eThe bytes\u003c/param\u003e\n/// \u003cparam name=\"timeOut\"\u003eThe timeout\u003c/param\u003e\n/// \u003creturns\u003e\u003c/returns\u003e\nValueTask AddBuffer(IEnumerable\u003cbyte\u003e bytes, TimeSpan timeOut);\n/// \u003csummary\u003e\n/// Adds a buffer to javascript side\n/// \u003c/summary\u003e\n/// \u003cparam name=\"stream\"\u003eThe stream\u003c/param\u003e\n/// \u003creturns\u003e\u003c/returns\u003e\nValueTask AddBuffer(Stream stream);\n/// \u003csummary\u003e\n/// Adds a buffer to javascript side\n/// \u003c/summary\u003e\n/// \u003cparam name=\"stream\"\u003eThe stream\u003c/param\u003e\n/// \u003cparam name=\"cancellationToken\"\u003eThe cancellation token\u003c/param\u003e\n/// \u003creturns\u003e\u003c/returns\u003e\nValueTask AddBuffer(Stream stream, CancellationToken cancellationToken);\n/// \u003csummary\u003e\n/// Adds a buffer to javascript side\n/// \u003c/summary\u003e\n/// \u003cparam name=\"stream\"\u003eThe stream\u003c/param\u003e\n/// \u003cparam name=\"streamReadcancellationToken\"\u003eThe cancellation token\u003c/param\u003e\n/// \u003cparam name=\"timeOutJavaScript\"\u003eThe timeout\u003c/param\u003e\n/// \u003creturns\u003e\u003c/returns\u003e\nValueTask AddBuffer(Stream stream, CancellationToken streamReadcancellationToken, TimeSpan timeOutJavaScript);\n/// \u003csummary\u003e\n/// Checks wether there is any buffer loaded in the JavaScript side.\n/// \u003c/summary\u003e\n/// \u003creturns\u003e\u003c/returns\u003e\nValueTask\u003cbool\u003e AnyBuffer();\n/// \u003csummary\u003e\n/// Gets the buffers count loaded in the JavaScript side.\n/// \u003c/summary\u003e\n/// \u003creturns\u003e\u003c/returns\u003e\nValueTask\u003cint\u003e BuffersCount();\n/// \u003csummary\u003e\n/// Clears the buffers in javascript side\n/// \u003c/summary\u003e\n/// \u003creturns\u003e\u003c/returns\u003e\nValueTask ClearBuffers();\n/// \u003csummary\u003e\n/// Merges and downloads all pending buffers into a single file in the browser. This method should be called when the added buffers where a base64 string type. \n/// \u003c/summary\u003e\n/// \u003cparam name=\"fileName\"\u003eThe filename\u003c/param\u003e\n/// \u003cparam name=\"contentType\"\u003eThe content type\u003c/param\u003e\n/// \u003creturns\u003e\u003c/returns\u003e\nValueTask\u003cDownloadFileResult\u003e DownloadBase64Buffers(string fileName, string contentType = \"application/octet-stream\");\n/// \u003csummary\u003e\n/// Merges and downloads all pending buffers into a single file in the browser. This method should be called when the added buffers where a base64 string type. \n/// \u003c/summary\u003e\n/// \u003cparam name=\"fileName\"\u003eThe filename\u003c/param\u003e\n/// \u003cparam name=\"cancellationToken\"\u003eThe cancellation token\u003c/param\u003e\n/// \u003cparam name=\"contentType\"\u003eThe content type\u003c/param\u003e\n/// \u003creturns\u003e\u003c/returns\u003e\nValueTask\u003cDownloadFileResult\u003e DownloadBase64Buffers(string fileName, CancellationToken cancellationToken, string contentType = \"application/octet-stream\");\n/// \u003csummary\u003e\n/// Merges and downloads all pending buffers into a single file in the browser. This method should be called when the added buffers where a base64 string type. \n/// \u003c/summary\u003e\n/// \u003cparam name=\"fileName\"\u003eThe filename\u003c/param\u003e\n/// \u003cparam name=\"timeOut\"\u003eThe timeout\u003c/param\u003e\n/// \u003cparam name=\"contentType\"\u003eThe content type\u003c/param\u003e\n/// \u003creturns\u003e\u003c/returns\u003e\nValueTask\u003cDownloadFileResult\u003e DownloadBase64Buffers(string fileName, TimeSpan timeOut, string contentType = \"application/octet-stream\");\n/// \u003csummary\u003e\n/// Merges and downloads all pending buffers into a single file in the browser. This method should be called when the added buffers where a byte array, byte enumerable or a stream types. \n/// \u003c/summary\u003e\n/// \u003cparam name=\"fileName\"\u003eThe filename\u003c/param\u003e\n/// \u003cparam name=\"contentType\"\u003eThe content type\u003c/param\u003e\n/// \u003creturns\u003e\u003c/returns\u003e\nValueTask\u003cDownloadFileResult\u003e DownloadBinaryBuffers(string fileName, string contentType = \"application/octet-stream\");\n/// \u003csummary\u003e\n/// Merges and downloads all pending buffers into a single file in the browser. This method should be called when the added buffers where a byte array, byte enumerable or a stream types. \n/// \u003c/summary\u003e\n/// \u003cparam name=\"fileName\"\u003eThe filename\u003c/param\u003e\n/// \u003cparam name=\"cancellationToken\"\u003eThe cancellation token\u003c/param\u003e\n/// \u003cparam name=\"contentType\"\u003eThe content type\u003c/param\u003e\n/// \u003creturns\u003e\u003c/returns\u003e\nValueTask\u003cDownloadFileResult\u003e DownloadBinaryBuffers(string fileName, CancellationToken cancellationToken, string contentType = \"application/octet-stream\");\n/// \u003csummary\u003e\n/// Merges and downloads all pending buffers into a single file in the browser. This method should be called when the added buffers where a byte array, byte enumerable or a stream types. \n/// \u003c/summary\u003e\n/// \u003cparam name=\"fileName\"\u003eThe filename\u003c/param\u003e\n/// \u003cparam name=\"timeOut\"\u003eThe timeout\u003c/param\u003e\n/// \u003cparam name=\"contentType\"\u003eThe content type\u003c/param\u003e\n/// \u003creturns\u003e\u003c/returns\u003e\nValueTask\u003cDownloadFileResult\u003e DownloadBinaryBuffers(string fileName, TimeSpan timeOut, string contentType = \"application/octet-stream\");\n/// \u003csummary\u003e\n/// Download a file from blazor context to the browser \n/// \u003c/summary\u003e\n/// \u003cparam name=\"fileName\"\u003eThe filename\u003c/param\u003e\n/// \u003cparam name=\"bytesBase64\"\u003eThe bytes base 64 of the file\u003c/param\u003e\n/// \u003cparam name=\"contentType\"\u003eThe file content type\u003c/param\u003e\n/// \u003creturns\u003e\u003c/returns\u003e\nValueTask\u003cDownloadFileResult\u003e DownloadFile(string fileName, string bytesBase64, string contentType = \"application/octet-stream\");\n/// \u003csummary\u003e\n/// Download a file from blazor context to the browser \n/// \u003c/summary\u003e\n/// \u003cparam name=\"fileName\"\u003eThe filename\u003c/param\u003e\n/// \u003cparam name=\"bytesBase64\"\u003eThe bytes base 64 of the file\u003c/param\u003e\n/// \u003cparam name=\"cancellationToken\"\u003eThe cancellation token\u003c/param\u003e\n/// \u003cparam name=\"contentType\"\u003eThe file content type\u003c/param\u003e\n/// \u003creturns\u003e\u003c/returns\u003e\nValueTask\u003cDownloadFileResult\u003e DownloadFile(string fileName, string bytesBase64, CancellationToken cancellationToken, string contentType = \"application/octet-stream\");\n/// \u003csummary\u003e\n/// Download a file from blazor context to the browser \n/// \u003c/summary\u003e\n/// \u003cparam name=\"fileName\"\u003eThe filename\u003c/param\u003e\n/// \u003cparam name=\"bytesBase64\"\u003eThe bytes base 64 of the file\u003c/param\u003e\n/// \u003cparam name=\"timeOut\"\u003eThe timeout of the operation\u003c/param\u003e\n/// \u003cparam name=\"contentType\"\u003eThe file content type\u003c/param\u003e\n/// \u003creturns\u003e\u003c/returns\u003e\nValueTask\u003cDownloadFileResult\u003e DownloadFile(string fileName, string bytesBase64, TimeSpan timeOut, string contentType = \"application/octet-stream\");\n/// \u003csummary\u003e\n/// Download a file from blazor context to the browser\n/// \u003c/summary\u003e\n/// \u003cparam name=\"fileName\"\u003eThe filename\u003c/param\u003e\n/// \u003cparam name=\"bytes\"\u003eThe bytes of the file\u003c/param\u003e\n/// \u003cparam name=\"contentType\"\u003eThe file content type\u003c/param\u003e\n/// \u003creturns\u003e\u003c/returns\u003e\nValueTask\u003cDownloadFileResult\u003e DownloadFile(string fileName, byte[] bytes, string contentType = \"application/octet-stream\");\n/// \u003csummary\u003e\n/// Download a file from blazor context to the browser\n/// \u003c/summary\u003e\n/// \u003cparam name=\"fileName\"\u003eThe filename\u003c/param\u003e\n/// \u003cparam name=\"bytes\"\u003eThe bytes of the file\u003c/param\u003e\n/// \u003cparam name=\"cancellationToken\"\u003eThe cancellation token\u003c/param\u003e\n/// \u003cparam name=\"contentType\"\u003eThe file content type\u003c/param\u003e\n/// \u003creturns\u003e\u003c/returns\u003e\nValueTask\u003cDownloadFileResult\u003e DownloadFile(string fileName, byte[] bytes, CancellationToken cancellationToken, string contentType = \"application/octet-stream\");\n/// \u003csummary\u003e\n/// Download a file from blazor context to the browser\n/// \u003c/summary\u003e\n/// \u003cparam name=\"fileName\"\u003eThe filename\u003c/param\u003e\n/// \u003cparam name=\"bytes\"\u003eThe bytes of the file\u003c/param\u003e\n/// \u003cparam name=\"timeOut\"\u003eThe timeout of the operation\u003c/param\u003e\n/// \u003cparam name=\"contentType\"\u003eThe file content type\u003c/param\u003e\n/// \u003creturns\u003e\u003c/returns\u003e\nValueTask\u003cDownloadFileResult\u003e DownloadFile(string fileName, byte[] bytes, TimeSpan timeOut, string contentType = \"application/octet-stream\");\n/// \u003csummary\u003e\n/// Download a file from blazor context to the browser\n/// \u003c/summary\u003e\n/// \u003cparam name=\"fileName\"\u003eThe filename\u003c/param\u003e\n/// \u003cparam name=\"bytes\"\u003eThe bytes of the file\u003c/param\u003e\n/// \u003cparam name=\"contentType\"\u003eThe file content type\u003c/param\u003e\n/// \u003creturns\u003e\u003c/returns\u003e\nValueTask\u003cDownloadFileResult\u003e DownloadFile(string fileName, IEnumerable\u003cbyte\u003e bytes, string contentType = \"application/octet-stream\");\n/// \u003csummary\u003e\n/// Download a file from blazor context to the browser\n/// \u003c/summary\u003e\n/// \u003cparam name=\"fileName\"\u003eThe filename\u003c/param\u003e\n/// \u003cparam name=\"bytes\"\u003eThe bytes of the file\u003c/param\u003e\n/// \u003cparam name=\"cancellationToken\"\u003eThe cancellation token\u003c/param\u003e\n/// \u003cparam name=\"contentType\"\u003eThe file content type\u003c/param\u003e\n/// \u003creturns\u003e\u003c/returns\u003e\nValueTask\u003cDownloadFileResult\u003e DownloadFile(string fileName, IEnumerable\u003cbyte\u003e bytes, CancellationToken cancellationToken, string contentType = \"application/octet-stream\");\n/// \u003csummary\u003e\n/// Download a file from blazor context to the browser\n/// \u003c/summary\u003e\n/// \u003cparam name=\"fileName\"\u003eThe filename\u003c/param\u003e\n/// \u003cparam name=\"bytes\"\u003eThe bytes of the file\u003c/param\u003e\n/// \u003cparam name=\"timeOut\"\u003eThe timeout of the operation\u003c/param\u003e\n/// \u003cparam name=\"contentType\"\u003eThe file content type\u003c/param\u003e\n/// \u003creturns\u003e\u003c/returns\u003e\nValueTask\u003cDownloadFileResult\u003e DownloadFile(string fileName, IEnumerable\u003cbyte\u003e bytes, TimeSpan timeOut, string contentType = \"application/octet-stream\");\n/// \u003csummary\u003e\n///  Download a file from blazor context to the browser.\n/// \u003c/summary\u003e\n/// \u003cparam name=\"fileName\"\u003eThe filename\u003c/param\u003e\n/// \u003cparam name=\"stream\"\u003eThe stream of the file\u003c/param\u003e\n/// \u003cparam name=\"contentType\"\u003eThe file content type\u003c/param\u003e\n/// \u003creturns\u003e\u003c/returns\u003e\nValueTask\u003cDownloadFileResult\u003e DownloadFile(string fileName, Stream stream, string contentType = \"application/octet-stream\");\n/// \u003csummary\u003e\n///  Download a file from blazor context to the browser.\n/// \u003c/summary\u003e\n/// \u003cparam name=\"fileName\"\u003eThe filename\u003c/param\u003e\n/// \u003cparam name=\"stream\"\u003eThe stream of the file\u003c/param\u003e\n/// \u003cparam name=\"cancellationTokenBytesRead\"\u003eThe cancellation token when reading bytes\u003c/param\u003e\n/// \u003cparam name=\"cancellationTokenJavaScriptInterop\"\u003eThe cancellation token when executing javascript\u003c/param\u003e\n/// \u003cparam name=\"contentType\"\u003eThe file content type\u003c/param\u003e\n/// \u003creturns\u003e\u003c/returns\u003e\nValueTask\u003cDownloadFileResult\u003e DownloadFile(string fileName, Stream stream, CancellationToken cancellationTokenBytesRead, CancellationToken cancellationTokenJavaScriptInterop, string contentType = \"application/octet-stream\");\n/// \u003csummary\u003e\n///  Download a file from blazor context to the browser.\n/// \u003c/summary\u003e\n/// \u003cparam name=\"fileName\"\u003eThe filename\u003c/param\u003e\n/// \u003cparam name=\"stream\"\u003eThe stream of the file\u003c/param\u003e\n/// \u003cparam name=\"cancellationTokenBytesRead\"\u003eThe cancellation token when reading bytes\u003c/param\u003e\n/// \u003cparam name=\"timeOutJavaScriptInterop\"\u003eThe timeout when executing javascript\u003c/param\u003e\n/// \u003cparam name=\"contentType\"\u003eThe file content type\u003c/param\u003e\n/// \u003creturns\u003e\u003c/returns\u003e\nValueTask\u003cDownloadFileResult\u003e DownloadFile(string fileName, Stream stream, CancellationToken cancellationTokenBytesRead, TimeSpan timeOutJavaScriptInterop, string contentType = \"application/octet-stream\");\n/// \u003csummary\u003e\n/// Download a file from blazor context to the brower\n/// \u003c/summary\u003e\n/// \u003cparam name=\"fileName\"\u003eThe filename\u003c/param\u003e\n/// \u003cparam name=\"plainText\"\u003eThe plain text\u003c/param\u003e\n/// \u003cparam name=\"encoding\"\u003eThe enconding to use\u003c/param\u003e\n/// \u003cparam name=\"contentType\"\u003eThe file content type\u003c/param\u003e\n/// \u003cparam name=\"encoderShouldEmitIdentifier\"\u003etrue to specify that the System.Text.Encoding.GetPreamble method returns a Unicode byte order mark.\u003c/param\u003e\n/// \u003creturns\u003e\u003c/returns\u003e\nValueTask\u003cDownloadFileResult\u003e DownloadFileFromText(string fileName, string plainText, Encoding encoding, string contentType = \"text/plain\", bool encoderShouldEmitIdentifier = false);\n/// \u003csummary\u003e\n/// Download a file from blazor context to the brower\n/// \u003c/summary\u003e\n/// \u003cparam name=\"fileName\"\u003eThe filename\u003c/param\u003e\n/// \u003cparam name=\"plainText\"\u003eThe plain text\u003c/param\u003e\n/// \u003cparam name=\"encoding\"\u003eThe enconding to use\u003c/param\u003e\n/// \u003cparam name=\"cancellationToken\"\u003eThe cancellation token\u003c/param\u003e\n/// \u003cparam name=\"contentType\"\u003eThe file content type\u003c/param\u003e\n/// \u003cparam name=\"encoderShouldEmitIdentifier\"\u003etrue to specify that the System.Text.Encoding.GetPreamble method returns a Unicode byte order mark.\u003c/param\u003e\n/// \u003creturns\u003e\u003c/returns\u003e\nValueTask\u003cDownloadFileResult\u003e DownloadFileFromText(string fileName, string plainText, Encoding encoding, CancellationToken cancellationToken, string contentType = \"text/plain\", bool encoderShouldEmitIdentifier = false);\n/// \u003csummary\u003e\n/// Download a file from blazor context to the brower\n/// \u003c/summary\u003e\n/// \u003cparam name=\"fileName\"\u003eThe filename\u003c/param\u003e\n/// \u003cparam name=\"plainText\"\u003eThe plain text\u003c/param\u003e\n/// \u003cparam name=\"encoding\"\u003eThe enconding to use\u003c/param\u003e\n/// \u003cparam name=\"timeOut\"\u003eThe timeout of the operation\u003c/param\u003e\n/// \u003cparam name=\"contentType\"\u003eThe file content type\u003c/param\u003e\n/// \u003cparam name=\"encoderShouldEmitIdentifier\"\u003etrue to specify that the System.Text.Encoding.GetPreamble method returns a Unicode byte order mark.\u003c/param\u003e\n/// \u003creturns\u003e\u003c/returns\u003e\nValueTask\u003cDownloadFileResult\u003e DownloadFileFromText(string fileName, string plainText, Encoding encoding, TimeSpan timeOut, string contentType = \"text/plain\", bool encoderShouldEmitIdentifier = false);\n/// \u003csummary\u003e\n/// Download a file from blazor context to the browser \n/// \u003c/summary\u003e\n/// \u003cparam name=\"fileName\"\u003eThe filename\u003c/param\u003e\n/// \u003cparam name=\"bytesBase64\"\u003eThe bytes base 64 of the file\u003c/param\u003e\n/// \u003cparam name=\"bufferSize\"\u003eThe buffer size\u003c/param\u003e\n/// \u003cparam name=\"contentType\"\u003eThe file content type\u003c/param\u003e\n/// \u003cparam name=\"progress\"\u003eThe progress percent of data transfered\u003c/param\u003e\n/// \u003creturns\u003e\u003c/returns\u003e\nValueTask\u003cDownloadFileResult\u003e DownloadFile(string fileName, string bytesBase64, int bufferSize = 32768, string contentType = \"application/octet-stream\", IProgress\u003cdouble\u003e? progress = null);\n/// \u003csummary\u003e\n/// Download a file from blazor context to the browser \n/// \u003c/summary\u003e\n/// \u003cparam name=\"fileName\"\u003eThe filename\u003c/param\u003e\n/// \u003cparam name=\"bytesBase64\"\u003eThe bytes base 64 of the file\u003c/param\u003e\n/// \u003cparam name=\"cancellationToken\"\u003eThe cancellation token\u003c/param\u003e\n/// \u003cparam name=\"bufferSize\"\u003eThe buffer size\u003c/param\u003e\n/// \u003cparam name=\"contentType\"\u003eThe file content type\u003c/param\u003e\n/// \u003cparam name=\"progress\"\u003eThe progress percent of data transfered\u003c/param\u003e\n/// \u003creturns\u003e\u003c/returns\u003e\nValueTask\u003cDownloadFileResult\u003e DownloadFile(string fileName, string bytesBase64, CancellationToken cancellationToken, int bufferSize = 32768, string contentType = \"application/octet-stream\", IProgress\u003cdouble\u003e? progress = null);\n/// \u003csummary\u003e\n/// Download a file from blazor context to the browser \n/// \u003c/summary\u003e\n/// \u003cparam name=\"fileName\"\u003eThe filename\u003c/param\u003e\n/// \u003cparam name=\"bytesBase64\"\u003eThe bytes base 64 of the file\u003c/param\u003e\n/// \u003cparam name=\"bufferSize\"\u003eThe buffer size\u003c/param\u003e\n/// \u003cparam name=\"timeOut\"\u003eThe timeout of the operation\u003c/param\u003e\n/// \u003cparam name=\"contentType\"\u003eThe file content type\u003c/param\u003e\n/// \u003cparam name=\"progress\"\u003eThe progress percent of data transfered\u003c/param\u003e\n/// \u003creturns\u003e\u003c/returns\u003e\nValueTask\u003cDownloadFileResult\u003e DownloadFile(string fileName, string bytesBase64, TimeSpan timeOut, int bufferSize = 32768, string contentType = \"application/octet-stream\", IProgress\u003cdouble\u003e? progress = null);\n/// \u003csummary\u003e\n/// Download a file from blazor context to the browser\n/// \u003c/summary\u003e\n/// \u003cparam name=\"fileName\"\u003eThe filename\u003c/param\u003e\n/// \u003cparam name=\"bytes\"\u003eThe bytes of the file\u003c/param\u003e\n/// \u003cparam name=\"bufferSize\"\u003eThe buffer size\u003c/param\u003e\n/// \u003cparam name=\"contentType\"\u003eThe file content type\u003c/param\u003e\n/// \u003cparam name=\"progress\"\u003eThe progress percent of data transfered\u003c/param\u003e\n/// \u003creturns\u003e\u003c/returns\u003e\nValueTask\u003cDownloadFileResult\u003e DownloadFile(string fileName, byte[] bytes, int bufferSize = 32768, string contentType = \"application/octet-stream\", IProgress\u003cdouble\u003e? progress = null);\n/// \u003csummary\u003e\n/// Download a file from blazor context to the browser\n/// \u003c/summary\u003e\n/// \u003cparam name=\"fileName\"\u003eThe filename\u003c/param\u003e\n/// \u003cparam name=\"bytes\"\u003eThe bytes of the file\u003c/param\u003e\n/// \u003cparam name=\"cancellationToken\"\u003eThe cancellation token\u003c/param\u003e\n/// \u003cparam name=\"bufferSize\"\u003eThe buffer size\u003c/param\u003e\n/// \u003cparam name=\"contentType\"\u003eThe file content type\u003c/param\u003e\n/// \u003cparam name=\"progress\"\u003eThe progress percent of data transfered\u003c/param\u003e\n/// \u003creturns\u003e\u003c/returns\u003e\nValueTask\u003cDownloadFileResult\u003e DownloadFile(string fileName, byte[] bytes, CancellationToken cancellationToken, int bufferSize = 32768, string contentType = \"application/octet-stream\", IProgress\u003cdouble\u003e? progress = null);\n/// \u003csummary\u003e\n/// Download a file from blazor context to the browser\n/// \u003c/summary\u003e\n/// \u003cparam name=\"fileName\"\u003eThe filename\u003c/param\u003e\n/// \u003cparam name=\"bytes\"\u003eThe bytes of the file\u003c/param\u003e\n/// \u003cparam name=\"timeOut\"\u003eThe timeout of the operation\u003c/param\u003e\n/// \u003cparam name=\"bufferSize\"\u003eThe buffer size\u003c/param\u003e\n/// \u003cparam name=\"contentType\"\u003eThe file content type\u003c/param\u003e\n/// \u003cparam name=\"progress\"\u003eThe progress percent of data transfered\u003c/param\u003e\n/// \u003creturns\u003e\u003c/returns\u003e\nValueTask\u003cDownloadFileResult\u003e DownloadFile(string fileName, byte[] bytes, TimeSpan timeOut, int bufferSize = 32768, string contentType = \"application/octet-stream\", IProgress\u003cdouble\u003e? progress = null);\n/// \u003csummary\u003e\n/// Download a file from blazor context to the browser\n/// \u003c/summary\u003e\n/// \u003cparam name=\"fileName\"\u003eThe filename\u003c/param\u003e\n/// \u003cparam name=\"bytes\"\u003eThe bytes of the file\u003c/param\u003e\n/// \u003cparam name=\"bufferSize\"\u003eThe buffer size\u003c/param\u003e\n/// \u003cparam name=\"contentType\"\u003eThe file content type\u003c/param\u003e\n/// \u003cparam name=\"progress\"\u003eThe progress percent of data transfered\u003c/param\u003e\n/// \u003creturns\u003e\u003c/returns\u003e\nValueTask\u003cDownloadFileResult\u003e DownloadFile(string fileName, IEnumerable\u003cbyte\u003e bytes, int bufferSize = 32768, string contentType = \"application/octet-stream\", IProgress\u003cdouble\u003e? progress = null);\n/// \u003csummary\u003e\n/// Download a file from blazor context to the browser\n/// \u003c/summary\u003e\n/// \u003cparam name=\"fileName\"\u003eThe filename\u003c/param\u003e\n/// \u003cparam name=\"bytes\"\u003eThe bytes of the file\u003c/param\u003e\n/// \u003cparam name=\"cancellationToken\"\u003eThe cancellation token\u003c/param\u003e\n/// \u003cparam name=\"bufferSize\"\u003eThe buffer size\u003c/param\u003e\n/// \u003cparam name=\"contentType\"\u003eThe file content type\u003c/param\u003e\n/// \u003cparam name=\"progress\"\u003eThe progress percent of data transfered\u003c/param\u003e\n/// \u003creturns\u003e\u003c/returns\u003e\nValueTask\u003cDownloadFileResult\u003e DownloadFile(string fileName, IEnumerable\u003cbyte\u003e bytes, CancellationToken cancellationToken, int bufferSize = 32768, string contentType = \"application/octet-stream\", IProgress\u003cdouble\u003e? progress = null);\n/// \u003csummary\u003e\n/// Download a file from blazor context to the browser\n/// \u003c/summary\u003e\n/// \u003cparam name=\"fileName\"\u003eThe filename\u003c/param\u003e\n/// \u003cparam name=\"bytes\"\u003eThe bytes of the file\u003c/param\u003e\n/// \u003cparam name=\"timeOut\"\u003eThe timeout of the operation\u003c/param\u003e\n/// \u003cparam name=\"bufferSize\"\u003eThe buffer size\u003c/param\u003e\n/// \u003cparam name=\"contentType\"\u003eThe file content type\u003c/param\u003e\n/// \u003cparam name=\"progress\"\u003eThe progress percent of data transfered\u003c/param\u003e\n/// \u003creturns\u003e\u003c/returns\u003e\nValueTask\u003cDownloadFileResult\u003e DownloadFile(string fileName, IEnumerable\u003cbyte\u003e bytes, TimeSpan timeOut, int bufferSize = 32768, string contentType = \"application/octet-stream\", IProgress\u003cdouble\u003e? progress = null);\n/// \u003csummary\u003e\n///  Download a file from blazor context to the browser. Please take note that this method doesn't reset the stream position to 0.\n/// \u003c/summary\u003e\n/// \u003cparam name=\"fileName\"\u003eThe filename\u003c/param\u003e\n/// \u003cparam name=\"stream\"\u003eThe stream of the file\u003c/param\u003e\n/// \u003cparam name=\"bufferSize\"\u003eThe buffer size\u003c/param\u003e\n/// \u003cparam name=\"contentType\"\u003eThe file content type\u003c/param\u003e\n/// \u003cparam name=\"progress\"\u003eThe progress percent of data transfered\u003c/param\u003e\n/// \u003creturns\u003e\u003c/returns\u003e\nValueTask\u003cDownloadFileResult\u003e DownloadFile(string fileName, Stream stream, int bufferSize = 32768, string contentType = \"application/octet-stream\", IProgress\u003cdouble\u003e? progress = null);\n/// \u003csummary\u003e\n///  Download a file from blazor context to the browser. Please take note that this method doesn't reset the stream position to 0.\n/// \u003c/summary\u003e\n/// \u003cparam name=\"fileName\"\u003eThe filename\u003c/param\u003e\n/// \u003cparam name=\"stream\"\u003eThe stream of the file\u003c/param\u003e\n/// \u003cparam name=\"cancellationTokenBytesRead\"\u003eThe cancellation token when reading bytes\u003c/param\u003e\n/// \u003cparam name=\"cancellationTokenJavaScriptInterop\"\u003eThe cancellation token when executing javascript\u003c/param\u003e\n/// \u003cparam name=\"bufferSize\"\u003eThe buffer size\u003c/param\u003e\n/// \u003cparam name=\"contentType\"\u003eThe file content type\u003c/param\u003e\n/// \u003cparam name=\"progress\"\u003eThe progress percent of data transfered\u003c/param\u003e\n/// \u003creturns\u003e\u003c/returns\u003e\nValueTask\u003cDownloadFileResult\u003e DownloadFile(string fileName, Stream stream, CancellationToken cancellationTokenBytesRead, CancellationToken cancellationTokenJavaScriptInterop, int bufferSize = 32768, string contentType = \"application/octet-stream\", IProgress\u003cdouble\u003e? progress = null);\n/// \u003csummary\u003e\n///  Download a file from blazor context to the browser. Please take note that this method doesn't reset the stream position to 0.\n/// \u003c/summary\u003e\n/// \u003cparam name=\"fileName\"\u003eThe filename\u003c/param\u003e\n/// \u003cparam name=\"stream\"\u003eThe stream of the file\u003c/param\u003e\n/// \u003cparam name=\"cancellationTokenBytesRead\"\u003eThe cancellation token when reading bytes\u003c/param\u003e\n/// \u003cparam name=\"timeOutJavaScriptInterop\"\u003eThe timeout when executing javascript\u003c/param\u003e\n/// \u003cparam name=\"bufferSize\"\u003eThe buffer size\u003c/param\u003e\n/// \u003cparam name=\"contentType\"\u003eThe file content type\u003c/param\u003e\n/// \u003cparam name=\"progress\"\u003eThe progress percent of data transfered\u003c/param\u003e\n/// \u003creturns\u003e\u003c/returns\u003e\nValueTask\u003cDownloadFileResult\u003e DownloadFile(string fileName, Stream stream, CancellationToken cancellationTokenBytesRead, TimeSpan timeOutJavaScriptInterop, int bufferSize = 32768, string contentType = \"application/octet-stream\", IProgress\u003cdouble\u003e? progress = null);\n/// \u003csummary\u003e\n/// Download a file from blazor context to the brower\n/// \u003c/summary\u003e\n/// \u003cparam name=\"fileName\"\u003eThe filename\u003c/param\u003e\n/// \u003cparam name=\"plainText\"\u003eThe plain text\u003c/param\u003e\n/// \u003cparam name=\"encoding\"\u003eThe enconding to use\u003c/param\u003e\n/// \u003cparam name=\"bufferSize\"\u003eThe buffer size\u003c/param\u003e\n/// \u003cparam name=\"contentType\"\u003eThe file content type\u003c/param\u003e\n/// \u003cparam name=\"progress\"\u003eThe progress percent of data transfered\u003c/param\u003e\n/// \u003cparam name=\"encoderShouldEmitIdentifier\"\u003etrue to specify that the System.Text.Encoding.GetPreamble method returns a Unicode byte order mark.\u003c/param\u003e\n/// \u003creturns\u003e\u003c/returns\u003e\nValueTask\u003cDownloadFileResult\u003e DownloadFileFromText(string fileName, string plainText, Encoding encoding, int bufferSize = 32768, string contentType = \"text/plain\", IProgress\u003cdouble\u003e? progress = null, bool encoderShouldEmitIdentifier = false);\n/// \u003csummary\u003e\n/// Download a file from blazor context to the brower\n/// \u003c/summary\u003e\n/// \u003cparam name=\"fileName\"\u003eThe filename\u003c/param\u003e\n/// \u003cparam name=\"plainText\"\u003eThe plain text\u003c/param\u003e\n/// \u003cparam name=\"encoding\"\u003eThe enconding to use\u003c/param\u003e\n/// \u003cparam name=\"cancellationToken\"\u003eThe cancellation token\u003c/param\u003e\n/// \u003cparam name=\"bufferSize\"\u003eThe buffer size\u003c/param\u003e\n/// \u003cparam name=\"contentType\"\u003eThe file content type\u003c/param\u003e\n/// \u003cparam name=\"progress\"\u003eThe progress percent of data transfered\u003c/param\u003e\n/// \u003cparam name=\"encoderShouldEmitIdentifier\"\u003etrue to specify that the System.Text.Encoding.GetPreamble method returns a Unicode byte order mark.\u003c/param\u003e\n/// \u003creturns\u003e\u003c/returns\u003e\nValueTask\u003cDownloadFileResult\u003e DownloadFileFromText(string fileName, string plainText, Encoding encoding, CancellationToken cancellationToken, int bufferSize = 32768, string contentType = \"text/plain\", IProgress\u003cdouble\u003e? progress = null, bool encoderShouldEmitIdentifier = false);\n/// \u003csummary\u003e\n/// Download a file from blazor context to the brower\n/// \u003c/summary\u003e\n/// \u003cparam name=\"fileName\"\u003eThe filename\u003c/param\u003e\n/// \u003cparam name=\"plainText\"\u003eThe plain text\u003c/param\u003e\n/// \u003cparam name=\"encoding\"\u003eThe enconding to use\u003c/param\u003e\n/// \u003cparam name=\"timeOut\"\u003eThe timeout of the operation\u003c/param\u003e\n/// \u003cparam name=\"bufferSize\"\u003eThe buffer size\u003c/param\u003e\n/// \u003cparam name=\"contentType\"\u003eThe file content type\u003c/param\u003e\n/// \u003cparam name=\"progress\"\u003eThe progress percent of data transfered\u003c/param\u003e\n/// \u003cparam name=\"encoderShouldEmitIdentifier\"\u003etrue to specify that the System.Text.Encoding.GetPreamble method returns a Unicode byte order mark.\u003c/param\u003e\n/// \u003creturns\u003e\u003c/returns\u003e\nValueTask\u003cDownloadFileResult\u003e DownloadFileFromText(string fileName, string plainText, Encoding encoding, TimeSpan timeOut, int bufferSize = 32768, string contentType = \"text/plain\", IProgress\u003cdouble\u003e? progress = null, bool encoderShouldEmitIdentifier = false);\n```\n\n### Performance Considerations and Understandings\n\nRegarding on some performance test I have done in this library is that, `base64` string and `byte[]` performs faster than `Stream` always. \n\nSince there is not direct conversion between from c# `Stream` to a JavaScript object its a little more expensive this task. \n\nWhen its `base64` this is the most simple data type to transfer and work with it. \n\n`byte[]` gets transformed into `base64` string when transfered to JavaScript and for some reason it won't work properly when encoding cause its `base64` representation turns to be something else when going after the second partition when gets encoded to `base64` string. (If anyone knows how to fix or workaround this make a pull request) \n\nBased on the las sentence, a list of bytes gets passed down from c#  to JavaScript as an array of intergers with the bytes representation on JavaScript and this is the reason why I send a `IList\u003cbyte\u003e` rather than `byte[]` internally to JavaScript. \n\nThe binary representation seems to perform very well since we just needed to call `Uint8Array` and push the binary representation entirely into the array to then pass it down to the JavaScript native `Blob` object. \n\n\u003cb\u003eTake note that you may use the overload methods with buffers if you are sending big files over the wire and also that browsers have their own limitations on [JavaScript Max Blob Size](https://stackoverflow.com/questions/28307789/is-there-any-limitation-on-javascript-max-blob-size) based on the device hardware, browser vendor and the OS.\u003c/b\u003e\n\n\u003cb\u003eTake note also that blazor server side uses [Signal R](https://docs.microsoft.com/en-us/aspnet/core/signalr/security?view=aspnetcore-3.1#buffer-management) and has its data transfer (buffer) limitations.\u003c/b\u003e\n\n## License\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farivera12%2FBlazorDownloadFile","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farivera12%2FBlazorDownloadFile","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farivera12%2FBlazorDownloadFile/lists"}