Skip to content

Instantly share code, notes, and snippets.

@arxipovdev
Last active September 16, 2022 14:14
Show Gist options
  • Select an option

  • Save arxipovdev/1422ae9a5b7675b3219966975ae4bc2a to your computer and use it in GitHub Desktop.

Select an option

Save arxipovdev/1422ae9a5b7675b3219966975ae4bc2a to your computer and use it in GitHub Desktop.
[Upload files to server .net core use axios] #.net #c# #axios

Controller

[ApiController]
[Route("api/[controller]")]
public class TestController : Controller
{
    [HttpPost]
    public async Task<IActionResult> Post([FromForm] Data data)
    {
        return Ok(data);
    }
    
    public class Data
    {
        public string Title { get; set; }

        public string Description { get; set; }

        public IEnumerable<IFormFile> Files { get; set; }
    }
}

JS

const formBody = new FormData();
formBody.append('Title', 'title');
formBody.append('Description', 'description');
this.files.forEach(file => formBody.append('Files', file));
const res = await axios.post('http://localhost:5000/api/Test', formBody);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment