我正在尝试使用上传图片MVC 6; 但是,我无法找到班级HttpPostedFileBase.我检查过GitHub,没有运气.有谁知道上传文件的正确方法MVC6?
我正在尝试使用ajax请求使用aspnet核心上传文件.在以前的.net版本中我曾经使用过
foreach (string fileName in Request.Files)
{
HttpPostedFileBase file = Request.Files[fileName];
//Save file content goes here
fName = file.FileName;
(...)
Run Code Online (Sandbox Code Playgroud)
但现在它在request.files显示错误我怎么能让它工作?我搜索并发现httppostedfile已更改为iformfile但如何处理request.files?
你如何形成你应该从请求中接收一个file和一个text值的动作方法的参数?
我试过这个
public string Post([FromBody]string name, [FromBody]IFormFile imageFile)
Run Code Online (Sandbox Code Playgroud)
并尝试从Postman打它,但它给了我500 Internal Server Error.我也无法调试它,因为它永远不会触及我放置断点的action方法中的第一个语句.
任何想法我们如何解析基于边界的请求并提取文件和其他文本字段?我是ASP.NET Core的新手.
我正在尝试在ASP.NET 5中上传文件,但我在互联网上看到的两种方式都失败了.使用XMLHttpRequest,这是我的服务器端代码:
public async Task<ActionResult> UploadSWF()
{
StreamReader reader = new StreamReader(Request.Body);
var text = await reader.ReadToEndAsync();
return View();
}
Run Code Online (Sandbox Code Playgroud)
[编辑1]:我的客户方:
var client = new XMLHttpRequest();
function upload()
{
var file = document.getElementById("uploadfile");
var formData = new FormData();
formData.append("upload", file.files[0]);
client.open("post", "/Home/UploadSWF", true);
//client.setRequestHeader("Content-Type", "multipart/form-data");
client.setRequestHeader("Content-Type", "application/x-shockwave-flash");
client.send(formData);
}
Run Code Online (Sandbox Code Playgroud)
但我唯一能从中得到的是:
------ WebKitFormBoundaryX1h5stVbtaNe6nFw Content-Disposition:form-data; NAME = "上传"; filename ="data.swf"内容类型:application/x-shockwave-flash CWS;"
[编辑2]:这是我如何得到这个代码:
public ActionResult UploadSWF()
{
Stream bodyStream = Context.Request.Body;
var sr = new StreamReader(bodyStream);
var test = sr.ReadToEnd();
return …Run Code Online (Sandbox Code Playgroud)