| Name | Message | Date |
|---|---|---|
| 📁 Admin | 13 days ago | |
| 📄 Home.razor | 13 days ago | |
| 📄 NotFound.razor | 13 days ago | |
| 📄 UploadTest.razor | 13 days ago |
📄
MatDenDagen/Components/Pages/UploadTest.razor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
@page "/upload-test"
@using System.IO
@using MatDenDagen.Infrastructure.Storage.BlobStorage
@using Microsoft.AspNetCore.Http
@using System.Runtime.CompilerServices
@using Microsoft.AspNetCore.Mvc.Infrastructure
@using System.Threading
@inject BlobStorageService blobService
@implements IDisposable
<EditForm FormName="UploadTest" Model="@model" OnSubmit="@Submit" enctype="multipart/form-data" Enhance>
<p>
<label>
<span>Fil:</span>
<InputFile name="model.File" required />
</label>
</p>
<p>
<input type="submit" value="Ladda upp" />
</p>
</EditForm>
@if (uploadedId is not null)
{
<p>Filen har id: <code>@uploadedId</code></p>
}
@code {
private readonly CancellationTokenSource cts = new();
[SupplyParameterFromForm]
private UploadTestModel? model { get; set; }
private string? uploadedId { get; set; }
protected override void OnInitialized()
{
model ??= new();
}
private async Task Submit()
{
if (model?.File is not { } file)
{
return;
}
var result = await blobService.SaveBlob(file.OpenReadStream(), cts.Token);
uploadedId = result.Id;
}
public void Dispose()
{
cts.Cancel();
cts.Dispose();
}
private sealed class UploadTestModel
{
public IFormFile? File { get; set; }
}
}