Reputation: 1606
System.Web.UI.Request
is not available in .net core so the question is about the alternative of this namespace.
I need to read the file content for upload on server. in version 4.5 of .net, i was doing like HttpPostedFile file = Request.Files["content"];
but now this is not working in .net core. I need to know if there is any alternative of best example of file uploading in .net core please share.
following is my old code.
HttpPostedFile file = Request.Files["content"];
byte[] fileData = null;
using (var binaryReader = new BinaryReader(file.InputStream))
{
fileData = binaryReader.ReadBytes(file.ContentLength);
}
var fileName = Request.Form["fileName"];
FileBusiness.SaveFile(domain, new Guid(token), fileName, fileData, true);
Response.Write("Normal file uploaded");
I am asking for the upload file functionality in RC1 which is in think is not available in RC1 but i have found in .net core 1.0 RTM libraries. I need to know if there is any way to upload the file in .net core RC1?
Upvotes: 2
Views: 6347
Reputation: 16825
If you are using ASP.NET Core and enctype="multipart/form-data"
form then for reading uploaded file use IFormFile
(var file = Request.Form.Files["fileUpload"]
) and its CopyTo
, CopyToAsync
or OpenReadStream
methods.
Upvotes: 1