{"id":20600746,"url":"https://github.com/maraf/blazor-file-stream","last_synced_at":"2025-09-06T03:43:46.368Z","repository":{"id":225313854,"uuid":"765641002","full_name":"maraf/blazor-file-stream","owner":"maraf","description":"Blazor file streaming","archived":false,"fork":false,"pushed_at":"2024-03-01T13:06:43.000Z","size":9619,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-06T15:51:48.595Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"CSS","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/maraf.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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,"publiccode":null,"codemeta":null}},"created_at":"2024-03-01T10:25:24.000Z","updated_at":"2024-08-01T03:43:10.000Z","dependencies_parsed_at":null,"dependency_job_id":"5dfa2cc1-b0d6-47be-bb38-ccbb91c7f531","html_url":"https://github.com/maraf/blazor-file-stream","commit_stats":null,"previous_names":["maraf/blazor-file-stream"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/maraf/blazor-file-stream","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maraf%2Fblazor-file-stream","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maraf%2Fblazor-file-stream/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maraf%2Fblazor-file-stream/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maraf%2Fblazor-file-stream/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maraf","download_url":"https://codeload.github.com/maraf/blazor-file-stream/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maraf%2Fblazor-file-stream/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273854484,"owners_count":25180009,"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","status":"online","status_checked_at":"2025-09-06T02:00:13.247Z","response_time":2576,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-11-16T08:39:14.159Z","updated_at":"2025-09-06T03:43:46.345Z","avatar_url":"https://github.com/maraf.png","language":"CSS","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Blazor file streaming\n\nSample inspired by [documentation for Work with images in ASP.NET Core Blazor](https://learn.microsoft.com/en-us/aspnet/core/blazor/images) extended to work with any file type that browser is able to preview.\n\n## The code\n\nFrom Home.razor\n```csharp\nprivate async Task\u003c(Stream, string?)\u003e DownloadFileAsync(string url)\n{\n    var absoluteUrl = NavigationManager.ToAbsoluteUri(url);\n    Console.WriteLine($\"Downloading file from {absoluteUrl}\");\n\n    var response = await Http.GetAsync(absoluteUrl);\n    string? contentType = null;\n    if (response.Content.Headers.TryGetValues(\"Content-Type\", out var values))\n        contentType = values.FirstOrDefault();\n\n    return (await response.Content.ReadAsStreamAsync(), contentType);\n}\n\nprivate async Task ShowFileAsync(string url)\n{\n    var (imageStream, contentType) = await DownloadFileAsync(url);\n    \n    var dotnetImageStream = new DotNetStreamReference(imageStream);\n    await JS.InvokeVoidAsync(\"setIframeSource\", \"iframe\", dotnetImageStream, contentType);\n}\n```\n\nFrom index.html\n```javascript\nwindow.setIframeSource = async (imageElementId, imageStream, contentType) =\u003e {\n  const arrayBuffer = await imageStream.arrayBuffer();\n  let blobOptions = {};\n  if (contentType) {\n    blobOptions['type'] = contentType;\n  }\n  const blob = new Blob([arrayBuffer], blobOptions);\n  const url = URL.createObjectURL(blob);\n  const image = document.getElementById(imageElementId);\n  image.onload = () =\u003e {\n    URL.revokeObjectURL(url);\n  }\n  image.src = url;\n}\n```\n\n## Live\n\nRunning at https://maraf.github.io/blazor-file-stream/","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaraf%2Fblazor-file-stream","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaraf%2Fblazor-file-stream","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaraf%2Fblazor-file-stream/lists"}