uploading image asp.net Core

前端 未结 3 2044
挽巷
挽巷 2020-12-13 16:35

i am new to ASP.net COre and i would like to upload a file ( an image) and store it in a secific Folder. ihave been following this tuto (File uploads in ASP.NET Core) but i

3条回答
  •  执念已碎
    2020-12-13 17:05

    Just used the accepted answer from @Saineshwar, but did a little bit refactoring as one extension method to make it easy to use IFromFile

    public static string MakeFileUniqueName(this IFormFile formFile)
        {
            if (formFile.Length > 0)
            {
                string fileName =
                    ContentDispositionHeaderValue.Parse(formFile.ContentDisposition).FileName.Trim('"');
    
                // concatinating  FileName + FileExtension
                return Guid.NewGuid() + Path.GetExtension(fileName);      
            }
    
            return string.Empty;
        }
    

提交回复
热议问题