how to read files from a request .net core code example
Example 1: .net Core Get File Request
using System.IO;
var filePath = Path.GetTempFileName();
foreach (var formFile in Request.Form.Files)
{
if (formFile.Length > 0)
{
using (var inputStream = new FileStream(filePath, FileMode.Create))
{
await formFile.CopyToAsync(inputStream);
byte[] array = new byte[inputStream.Length];
inputStream.Seek(0, SeekOrigin.Begin);
inputStream.Read(array, 0, array.Length);
string fName = formFile.FileName;
}
}
}
Example 2: .net Core Get File Request
public FileResult GetFile(string fileid)
{
byte[] bytes = File.ReadAllBytes("C:\Temp.txt");
return File(bytes, System.Net.Mime.MediaTypeNames.Application.Octet, "Temp.txt");
}