public object BindModel(ModelBindingContext bindingContext) { var request = bindingContext.HttpContext.Request; var formUpload = request.Form.Files.Count > 0; // find filename var xFileName = request.Headers["X-File-Name"]; var qqFile = request.Form["qqfile"]; var formFilename = formUpload ? request.Form.Files[0].FileName : null; if (!string.IsNullOrEmpty(qqFile)) { formFilename = qqFile; } if (!string.IsNullOrEmpty(xFileName)) { formFilename = xFileName; } var upload = new FineUpload { Filename = formFilename, InputStream = formUpload ? request.Form.Files[0].OpenReadStream() : request.Body }; return(upload); }
public JsonResult UploadVideo([FromRoute] int productId, FineUpload fineUpload) { if (productId == 0) { throw new System.Exception("Invalid product"); } // считываем переданный файл в массив байтов using (var binaryReader = new BinaryReader(fineUpload.InputStream)) { var res = _videoService.AddVideo(productId, fineUpload.Filename, binaryReader); return(Json(new { success = true, linkId = res.Id })); } }