Skip to content

Commit 6a6c769

Browse files
Updated tests and fixed File.CreateAsync.
1 parent a97a0dc commit 6a6c769

3 files changed

Lines changed: 18 additions & 8 deletions

File tree

samples/KristofferStrube.Blazor.FileAPI.WasmExample/Pages/Index.razor

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,30 @@ In this sample we download an image using the <code>HttpClient</code> and create
1212
Using the methods from the <code>URL</code> interface we construct a <code>Blob URL</code> for the image and use that as the source for the img-tag below.
1313
<br />
1414
<img src="@blobURL" style="max-width:100%; max-height:50vh;" />
15+
<br />
16+
file name: @file?.Name
17+
<br />
18+
last modified: @file?.LastModified
19+
<br />
20+
content type: @file?.Type
21+
1522

1623
@code {
1724
private string blobURL = "";
25+
private FileInProcess? file;
1826

1927
protected override async Task OnInitializedAsync()
2028
{
21-
var mountainBytes = await HttpClient.GetByteArrayAsync("images/mountain.jpg");
22-
var blob = await Blob.CreateAsync(
29+
var imageName = "mountain.jpg";
30+
31+
var imageBytes = await HttpClient.GetByteArrayAsync($"images/{imageName}");
32+
file = await FileInProcess.CreateAsync(
2333
JSRuntime,
24-
blobParts: new BlobPart[] { new(mountainBytes) },
25-
options: new() { Type = "image/png" }
34+
fileBits: new BlobPart[] { new(imageBytes) },
35+
fileName: imageName,
36+
options: new() { Type = "image/png", LastModified = DateTime.Now }
2637
);
27-
blobURL = await URL.CreateObjectURLAsync(blob);
38+
blobURL = await URL.CreateObjectURLAsync(file);
2839
}
2940

3041
public async ValueTask DisposeAsync()

samples/KristofferStrube.Blazor.FileAPI.WasmExample/Pages/Slice.razor

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ Here we can see how we can slice a <code>Blob</code>. We construct a <code>Blob<
1616
<b>SliceAsync(start: 40):</b> @slice_start_40
1717
</div>
1818
<div>
19-
<b>SliceAsync(10, 20, "text/csv"):</b> @slice_start_40 with content type @slice10_20ContentType
19+
<b>SliceAsync(10, 20, "text/csv"):</b> @slice10_20 with content type @slice10_20ContentType
2020
</div>
2121

22-
2322
@code {
2423
string slice20_30 = "";
2524
string slice_end_10 = "";

src/KristofferStrube.Blazor.FileAPI/File.InProcess.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static async Task<FileInProcess> CreateAsync(IJSRuntime jSRuntime, IJSInP
3030
/// <param name="fileName">The name of the new file.</param>
3131
/// <param name="options">Options for constructing the new Blob which includes MIME type, line endings, and last modified date.</param>
3232
/// <returns></returns>
33-
public static new async Task<File> CreateAsync(IJSRuntime jSRuntime, IList<BlobPart> fileBits, string fileName, FilePropertyBag? options = null)
33+
public static new async Task<FileInProcess> CreateAsync(IJSRuntime jSRuntime, IList<BlobPart> fileBits, string fileName, FilePropertyBag? options = null)
3434
{
3535
IJSInProcessObjectReference inProcesshelper = await jSRuntime.GetInProcessHelperAsync();
3636
object?[]? jsFileBits = fileBits.Select<BlobPart, object?>(blobPart => blobPart.type switch

0 commit comments

Comments
 (0)