MVC 6 HttpPostedFileBase?

后端 未结 3 1506
不思量自难忘°
不思量自难忘° 2020-12-04 23:36

I am attempting to upload an image using MVC 6; however, I am not able to find the class HttpPostedFileBase. I have checked the GitHub

3条回答
  •  自闭症患者
    2020-12-05 00:34

    There is no HttpPostedFileBase in MVC6. You can use IFormFile instead.

    Example: https://github.com/aspnet/Mvc/blob/dev/test/WebSites/ModelBindingWebSite/Controllers/FileUploadController.cs

    Snippet from the above link:

    public FileDetails UploadSingle(IFormFile file)
    {
        FileDetails fileDetails;
        using (var reader = new StreamReader(file.OpenReadStream()))
        {
            var fileContent = reader.ReadToEnd();
            var parsedContentDisposition = ContentDispositionHeaderValue.Parse(file.ContentDisposition);
            fileDetails = new FileDetails
            {
                Filename = parsedContentDisposition.FileName,
                Content = fileContent
            };
        }
    
        return fileDetails;
    }
    

提交回复
热议问题