Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save oliveira-michel/d677ed4ba726bee05b509824f40b6c11 to your computer and use it in GitHub Desktop.
Save oliveira-michel/d677ed4ba726bee05b509824f40b6c11 to your computer and use it in GitHub Desktop.
Exemplo de Controller em .NET Core que recebe multipart/form-data
[HttpPost("arquivos")]
public ActionResult Student([FromForm]ArquivoModel arquivo)
{
string descricao = arquivo.Descricao;
string autor = arquivo.Autor;
var file = arquivo.Arquivo;
if (file.Length > 0) {
using (var fileStream = new FileStream(file.FileName, FileMode.Create)) {
file.CopyTo(fileStream);
//...
}
}
return Ok();
}
using Microsoft.AspNetCore.Http;
public class ArquivoModel {
public string Descricao { get; set; }
public string Autor { get; set; }
public IFormFile Arquivo { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment