-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e7bc4ad
commit ddb1c00
Showing
6 changed files
with
55 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 0 additions & 55 deletions
55
src/web/UnturnedStrikeWebBlazor/Shared/Components/InputFile.razor
This file was deleted.
Oops, something went wrong.
4 changes: 4 additions & 0 deletions
4
src/web/UnturnedStrikeWebBlazor/Shared/Components/InputImageFile.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<div class=""> | ||
<InputFile OnChange="HandleChange" accept="@Accept" /> | ||
<label>Choose file</label> | ||
</div> |
46 changes: 46 additions & 0 deletions
46
src/web/UnturnedStrikeWebBlazor/Shared/Components/InputImageFile.razor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using Microsoft.AspNetCore.Components.Forms; | ||
using Microsoft.AspNetCore.Components; | ||
using System.IO; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using System; | ||
using System.Net.Http.Headers; | ||
|
||
namespace UnturnedStrikeWebBlazor.Shared.Components | ||
{ | ||
public partial class InputImageFile | ||
{ | ||
[Parameter] | ||
public int? FileId { get; set; } | ||
[Parameter] | ||
public EventCallback<int?> FileIdChanged { get; set; } | ||
|
||
[Parameter] | ||
public string Accept { get; set; } | ||
|
||
[Inject] | ||
private HttpClient HttpClient { get; set; } | ||
|
||
private async Task HandleChange(InputFileChangeEventArgs args) | ||
{ | ||
IBrowserFile file = args.File; | ||
file = await file.RequestImageFileAsync("image/png", 800, 800); | ||
|
||
HttpRequestMessage msg = new(HttpMethod.Post, $"api/files") | ||
{ | ||
Content = new MultipartFormDataContent() | ||
}; | ||
|
||
var content = new StreamContent(file.OpenReadStream(30 * 1024 * 1024)); | ||
content.Headers.ContentType = MediaTypeHeaderValue.Parse(file.ContentType); | ||
(msg.Content as MultipartFormDataContent).Add(content, "file", file.Name); | ||
var response = await HttpClient.SendAsync(msg); | ||
|
||
if (response.IsSuccessStatusCode) | ||
{ | ||
FileId = Convert.ToInt32(await response.Content.ReadAsStringAsync()); | ||
await FileIdChanged.InvokeAsync(FileId); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters