'How to get path of the upload file from swagger?

I was following this post https://dejanstojanovic.net/aspnet/2021/april/handling-file-upload-in-aspnet-core-5-with-swagger-ui/ to learn how to upload files with swagger but I have a problem with files path.

I upload a file and it alaways send me a FileNotFoundException because IFormFile doesn't gives me path of file, it gives me only name. How can I get full path?

My code is dummy because I just get blocked on this issue but here it is:

        public void Import(IFormFile file)
        {
            XSSFWorkbook book;
            try
            {
                using (FileStream f = new FileStream(file.FileName, FileMode.Open, FileAccess.Read))
                {
                    book = new XSSFWorkbook(f);
                }
            }
            catch (FileNotFoundException)
            {
                Console.WriteLine("The file or directory cannot be found.");
            }

        }

Thank you!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source