How to upload file using web api core and angular 6

Last Reply 12 days ago By pandeyism

Posted 25 days ago

I am uploading files but not working with core web api.

var fileds = HttpContext.Request.Form.Files;
string folderName = "images";
string webRootPath = _hostingEnvironment.WebRootPath;
string newPath = Path.Combine(webRootPath, folderName);
if (!Directory.Exists(newPath))
{
Directory.CreateDirectory(newPath);
}
for (int i = 0; i < Request.Form.Files.Count; i++)
{
var myFile = Request.Form.Files[i];

if (myFile.Length > 0)
{
string fileName = ContentDispositionHeaderValue.Parse(myFile.ContentDisposition).FileName.Trim('"');
string fullPath = Path.Combine(newPath, fileName);
using (var stream = new FileStream(fullPath, FileMode.Create))
{
myFile.CopyTo(stream);
}
}
}

 

You are viewing reply posted by: pandeyism 12 days ago.
Posted 12 days ago

Hi vsaklani,

You cannot ask multiple queries within a question. This is against forum rules and necessary to maintain clean forum.
It is requested. Mark Answer the replies when question is answered and ask a new question as a responsible member to help fellow programmers around the world.
Note: If you don't mark answers, people will loose interest in your questions.