❔ Reading multiple files/folders inside root/subfolder
So since I'm working with Blazor WASM, apparently there is no way of reading files using
Directory.ReadAllFiles()
because the Directory
returns /
and nothing else. At runtime this won't read any folders or files.
So I was bound to using HttpClient
to do so.
However, the folder I'm reaching, will eventually have a CMS created number of files (All .md files) and I need a way of reading them all, and then using my parser for each files it finds.
I was hoping there was a way to do this with HttpClient
like for example client.GetAsync("localhost:0000/uploads/**/*.md");
but this seems like it isn't possible.
So I come here asking for help finding a way of readnig all .md
files inside the /uploads/
folder
(this can be /uploads/fpsettings/settings.md
, or /uploads/blogs/blog-slug.md
or many more.)12 Replies
Is this folder your webserver root, or what kind of server is it? For Blazor WASM it makes sense you can't read anything, since you're executing on the client side and it would be quite the security issue if you could suddenly snoop around a users drive
it sounds like you need an API or some other page that provides an index of available files
you can't in wasm
there is no server
to serve the files
It's probably nginx or similar serving everything I assume
nope, OP is on the right track, you need to http request them
Yeah that for sure
idk if we're getting confused by the attempt to make a HTTP request to the local machine
it's the same, just a local request
no issues
but is there actually a web server running? or is that a blind attempt to access the filesystem using something incorrectly
as i understood it there is, but it's running blazor wasm
so it's a little bit weird
stuff is downloaded to client and there is no server
and no file system
don't forget to set the base url
you are still breaking the sandbox though, so it's not recommended
solution: get a proper web api and request resources from there
which you should do anyway, cause blazor wasm by itself is never enough
generally
Thank you all so much for this discussion
I’ve been looking high and low..
Thing is I’m using NetlifyCMS (now DecapCMS) not to be confused with netlify, inside my Blazor WASM project to generate the markdown files which hold the content for the components. So I need a way to parse the files into the content they provide.
I heard that if I generate everything of my WASM project as a static app, it should be able to reach the files with Directory?
I'm still not sure how to do this,
and I am also still not sure how to build a proper web API that can requests resources from there. Because then I'd have to have DecapCMS build all the markdown files to another API somewhere? Or maybe through the DevOps repository fetch or something...
But that would still create the new problem, I need to reach all files with
**/*.md
😅
So far this Blazor Project has taken me more than a month (and I'm taking the front-end from our old Svelte-Kit application)
And I keep running into issues with an actual CMS on Blazor WASM, headless, and no database, and still being able to use the data in the CMS generated files inside the components 😅 Why is Blazor such a PAIN sometimes 🤣Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.