Files


How to use the file related classes of the bit Butil?

Usage
The file features live in two classes. Inject the ones you need and use them like this:
@inject Bit.Butil.FileReader fileReader
@inject Bit.Butil.ObjectUrls objectUrls

@code {
    var text = await fileReader.ReadAsText(fileInput);
    var url = await objectUrls.Create(bytes, "image/png");
}
FileReader
The FileReader class wraps the FileReader API to read files selected in an <input type="file"> element as metadata, text, bytes or data URLs.

GetFileInfos:
Returns metadata (Name, Size and Type) for every file selected in the given input element (MDN).



ReadAsText:
Reads the first selected file as UTF-8 text (MDN).



ReadAsBytes:
Reads the first selected file as raw bytes (MDN).



ReadAsDataUrl:
Reads the first selected file as a base-64 data URL, convenient for image previews (MDN).



Clear:
Clears the input's selection (resets its files list) (MDN).

ObjectUrls
The ObjectUrls class wraps URL.createObjectURL and URL.revokeObjectURL for arbitrary byte payloads.

Create:
Creates a blob object URL from raw bytes plus an optional MIME type (MDN).



Revoke:
Revokes a previously created object URL to release its memory (MDN).