danroth27 / BlazorWeather

Blazor Weather
https://aka.ms/blazorweather
MIT License
247 stars 57 forks source link

How would I stream images in the MAUI App? #33

Open maptz opened 2 years ago

maptz commented 2 years ago

Hi @danroth27 ,

I was fiddling with this sample as my first experience of Blazor-Maui. This is looking super-cool!

I wanted to amend the app to serve images that are generated dynamically within the app (ie not by an external web-service) based on some weather-criteria. How would I go about doing this?

For e.g. imagine a weather image based on some data:

<img src="/img-generator-service?data=576587" />

How would I instantiate a service in the MAUI app that would mimic a webserver serving bytes to localhost?

e.g. to host something like:

public async Task<byte[]> ImgGeneratorService(string data);
//Or in the asp.net core pattern:
[HttpGet("img-generator-service")
public async Task<IActionResult> Get(string data);
nvmkpk commented 2 years ago

Content in blazor desktop and MAUI are served via IFileProvider. You would need to implement this interface to serve your generated content. However, with current release, you will not be able to plug in your implementation. This appears to be fixed but not released yet.

maptz commented 2 years ago

Ok. Makes sense. When you say "will not be able to plug in your implementation", you mean I can't register the IFileProvider service yet?

nvmkpk commented 2 years ago

BlazorWebView does not obtain IFileProvider from DI. It instantiates PhysicalFileProvider in a private method. The change that I see now is that they added a virtual method that we can override and return our own implementation to augment the current PhysicalFileProvider. You can see more details here: https://github.com/dotnet/maui/commit/55175b8c8b2159728ef7e7a06d4c334695f078eb#diff-0c065d47653e514388503b6e1cb075c67ce6fef6f6f955c9cdc78d51a47e5ecf