-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: Support non-text file reading #19
Comments
Hi @fixnil, 😊 This is related to issue #10 which is closed; you can read more about it there. In release 1.1.0 I added the possibility to stream to a FileSystemWritableFileStream by having it extend I am unsure whether this is inside this library's intended scope as it is a lot of work with the JS Blob which is a part of the File API. I am leaving this issue open so that I can track interest in solving this. I haven't decided whether or not this should be a part of this library or potentially spun out to its own library ( I have noted a couple of libraries that also work with JSInterop and Files which might be a help for future work. |
Sorry, I forgot to check those closed issues. Your solution works perfectly, my code is as follows: file.js export async function arrayBuffer(blob) {
var buffer = await blob.arrayBuffer();
var bytes = new Uint8Array(buffer);
return bytes;
} Index.razor var file = await _handle.GetFileAsync();
var module = await this.JSRuntime.InvokeAsync<IJSObjectReference>("import", "./file.js");
var bytes = await module.InvokeAsync<byte[]>("arrayBuffer", file.JSReference);
await System.IO.File.WriteAllBytesAsync(Filename, bytes); I don't know if I need to submit a PR as an alternative, before the official File API goes live? The code looks like this: Blazor.FileSystemAccess/src/KristofferStrube.Blazor.FileSystemAccess/Blob/Blob.cs // ...
public class Blob
{
// ...
public async Task<byte[]> ArrayBufferAsync()
{
return await helper.InvokeAsync<byte[]>("arrayBuffer", JSReference);
}
} |
By the way, I'll mention a small problem I found while using it. As you can see the code above, I had to use the fully qualified name because of the conflict. await System.IO.File.WriteAllBytesAsync(Filename, bytes); Is there a better solution here? Or is there another issue that needs to be created to discuss this. |
Hey @fixnil, Sounds good. You can create a PR with the solution if you want. I think it is pretty nice. If you add it to the existing helper js file and add the method to the If you submit a PR. Then I would like you to also create an example use case and add that to the demo on a new page. Regarding your problem with having to use the full namespace then I can recommend to either use |
And once we have a PR for this issue we can close it and I can create a new issue specifically for having |
I've added the method to the blob and added a simple case to prove it works, please review the code if you have time. Thanks. |
Hi @KristofferStrube,
I've recently had some issues reading non-text files into the browser.
Expect an API like this:
or like this:
Thank you for your work!
The text was updated successfully, but these errors were encountered: