Blazor.FileAPI icon indicating copy to clipboard operation
Blazor.FileAPI copied to clipboard

Feature request: Accessing webkitRelativePath and class extensibility

Open Enfis opened this issue 4 months ago β€’ 11 comments

First, thank you for your outstanding work on the Blazor.FileAPI library. It's truly a pleasure to use.

I'm working on a project that requires access to the webkitRelativePath property of the File object.

As the File class has an internal constructor, I've found that I cannot inherit from it to extend its functionality. This design forces me to use JSRuntime.InvokeAsync with the "getAttribute" helper to retrieve this simple property, which feels unnecessarily verbose for this use case.

Would you consider adding a public method to the IJSWrapper interface, or an extension method, that provides a more direct way to access common properties? For example, something like a GetPropertyAsync<T>() method. Or perhaps by adding a GetHelperReferenceAsync method to the BaseJSWrapper/IJSWrapper class?

This would greatly improve the API's usability and allow external classes to extend wrappers more elegantly.

Thank you for your time and for considering my request.

Enfis avatar Aug 21 '25 16:08 Enfis

Hey @Enfis, thanks for the kind words! πŸ˜ƒ

In the latest version of the package the constructor for File is actually protected instead of internal as I had also found that it was difficult to extend.

I imagine that you might be using the package together with some of my other packages, if you could share which version you are using of them then I might be able to help more. I’m currently working on upgrading Blazor.FileSystem to use the latest version of this library actually.

KristofferStrube avatar Aug 21 '25 20:08 KristofferStrube

Hello, and thank you for the fast reply!

My sincerest apologies; you are absolutely right.

It turns out there was a "lowest applicable version" issue with my NuGet packages: my project was inadvertently referencing version 0.3.0 through a transient dependency instead of the latest one. I have now resolved the issue.

Thank you again for your patience and for your work on these libraries.

Image

Enfis avatar Aug 22 '25 06:08 Enfis

It might not be possible to update it directly (even though it is within the same major version) as I made a binary-breaking change in Blazor.WebIDL some time ago. But I’m working on updating the file system and file system access packages to the newest version. I will update you here once that is done. Sorry for the inconvenience.

KristofferStrube avatar Aug 22 '25 06:08 KristofferStrube

Thanks for the feedback! I'm still learning Blazor and haven’t reached that part of the code yet. It would be great if a Blob/File could be encapsulated in a System.IO.Stream for both reading and writing - at least in WebAssembly mode.

Do you think I should ask this in a new thread?

Enfis avatar Aug 22 '25 11:08 Enfis

It has actually been requested before in #2 but if you would leave a comment there describing your use case/scenario then that would be helpful to track interest in the feature. πŸ™‚

KristofferStrube avatar Aug 22 '25 14:08 KristofferStrube

Hello again. I apologize if this is an oversight, but it appears the 'InProcess' version cannot be extended. The IJSInProcessObjectReference (inProcessHelper) constructor parameter is not publicly available outside of your assembly (canonically).

Enfis avatar Aug 25 '25 19:08 Enfis

I usually keep the extensions for my helpers internal yeah, but if you need it, then it's pretty simple: https://github.com/KristofferStrube/Blazor.FileAPI/blob/main/src/KristofferStrube.Blazor.FileAPI/Extensions/IJSRuntimeExtensions.cs#L12

KristofferStrube avatar Aug 25 '25 20:08 KristofferStrube

Hello, thanks for the clarification. I've also noticed the JavaScript code is quite simple. For a more complete and robust API, would you consider integrating the webkitRelativePath property directly into your library's File(InProcess) class? This would be very helpful for developers building directory pickers.

Enfis avatar Aug 25 '25 20:08 Enfis

Hey @Enfis, it seems like it is not defined in the File API, but that they plan to introduce it there if the File and Directory Entries API graduates to a real standard. So I don't think I will add it yet until/if it is ever added to the File API.

KristofferStrube avatar Aug 27 '25 20:08 KristofferStrube

Hello, thank you again for putting me on the right track πŸ˜‰πŸ‘ I'm still a novice in the JavaScript/Blazor world, unfortunately πŸ₯²

Enfis avatar Aug 28 '25 04:08 Enfis

@Enfis you are doing good! Keep staying curious. πŸ’ͺ

KristofferStrube avatar Aug 28 '25 05:08 KristofferStrube