Skip to content

Instantly share code, notes, and snippets.

@xximjasonxx
Created January 31, 2020 01:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xximjasonxx/82eec547c90118497be8ea5c0f6e968a to your computer and use it in GitHub Desktop.
Save xximjasonxx/82eec547c90118497be8ea5c0f6e968a to your computer and use it in GitHub Desktop.
public class FileController : ControllerBase
{
private readonly IConfiguration _configuration;
private readonly ILogger<FileController> _logger;
public FileController(ILogger<FileController> logger, IConfiguration configuration)
{
_logger = logger;
_configuration = configuration;
}
[HttpPost]
public async Task<IActionResult> Post(IFormFile file)
{
var uploadStream = file.OpenReadStream();
using (var fileStream = System.IO.File.Create(Path.Join(_configuration.GetValue<string>("OutputDirectory"), Guid.NewGuid().ToString())))
{
await uploadStream.CopyToAsync(fileStream);
}
return Ok();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment