Created
March 6, 2020 19:07
-
-
Save oliveira-michel/d677ed4ba726bee05b509824f40b6c11 to your computer and use it in GitHub Desktop.
Exemplo de Controller em .NET Core que recebe multipart/form-data
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
[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(); | |
} |
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
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