-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathFileController.cs
More file actions
27 lines (24 loc) · 886 Bytes
/
FileController.cs
File metadata and controls
27 lines (24 loc) · 886 Bytes
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
using Microsoft.AspNetCore.Mvc;
namespace BlazorServer.Controllers
{
[Route("[Controller]/[Action]")]
public class FileController : Controller
{
private readonly IConfiguration _config;
public FileController(IConfiguration config)
{
_config = config;
}
[HttpPost]
public async Task<IActionResult> Upload(List<IFormFile> files)
{
var file = files[0];
var root = _config.GetValue<string>(WebHostDefaults.ContentRootKey) ?? "";
var path = Path.Combine(root, $"wwwroot{Path.DirectorySeparatorChar}images", file.FileName);
FileStream filestream = new FileStream(path, FileMode.Create, FileAccess.Write);
await file.CopyToAsync(filestream);
filestream.Close();
return Content($"images/{file.FileName}");
}
}
}