MVC 6 HttpPostedFileBase?

编程入门 行业动态 更新时间:2024-10-20 05:27:18
本文介绍了MVC 6 HttpPostedFileBase?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试使用MVC 6上传图像;但是,我找不到类HttpPostedFileBase.我检查了GitHub,但没有任何运气.有人知道MVC6中上传文件的正确方法吗?

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 and did not have any luck. Does anyone know the correct way to upload a file in MVC6?

推荐答案

MVC 6使用了另一种机制来上传文件.您可以在 GitHub 或其他 资源.只需将IFormFile用作操作的参数或文件集合或 IFormFileCollection 如果要同时上传几个文件:

MVC 6 used another mechanism to upload files. You can get more examples on GitHub or other sources. Just use IFormFile as a parameter of your action or a collection of files or IFormFileCollection if you want upload few files in the same time:

public async Task<IActionResult> UploadSingle(IFormFile file) { FileDetails fileDetails; using (var reader = new StreamReader(file.OpenReadStream())) { var fileContent = reader.ReadToEnd(); var parsedContentDisposition = ContentDispositionHeaderValue.Parse(file.ContentDisposition); var fileName = parsedContentDisposition.FileName; } ... } [HttpPost] public async Task<IActionResult> UploadMultiple(ICollection<IFormFile> files) { var uploads = Path.Combine(_environment.WebRootPath,"uploads"); foreach(var file in files) { if(file.Length > 0) { var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"'); await file.SaveAsAsync(Path.Combine(uploads,fileName)); } ... } }

您可以在 asp中查看IFormFile的当前合同来源.另请参见 ContentDispositionHeaderValue .

You can see current contract of IFormFile in asp sources. See also ContentDispositionHeaderValue for additional file info.

更多推荐

MVC 6 HttpPostedFileBase?

本文发布于:2023-11-08 13:54:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1569562.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:MVC   HttpPostedFileBase

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!