I want to retrieve the path from a file but I can't find out how to retrieve the correct path. For example, when I upload a file from C:\Users\Valk\OneDrive\Desktop\Test.xlsx
, then I want to retrieve this path from the variable file
. I used ASP.NET Core 6 Web API.
[HttpPost]
public IActionResult Post(IFormFile file)
{
var filesPath = Directory.GetCurrentDirectory();
var fileName = Path.GetFileName(file.FileName);
var filePath = Path.Combine(filesPath, fileName);
return Ok();
}
CodePudding user response:
The IFormFile
does not provide the source file location on the client side.
Because of the action method is running on the server side and it makes no sense where the original file was located on the client side.
At the moment of execution of your public IActionResult Post(IFormFile file)
method you will no longer have access to the client side.