I have read all (most of) the entries in this forum regarding this matter and cannot seem to find my error. I want to upload a single file that I then pass onto another system. As multiple users could upload at the same time I use a GUID as a message ID and create a folder per user. Here I get the document (from a backend system where I would then like to upload the file to) and create the GUID:
public IActionResult Open()
{
ViewBag.MessageId = Guid.NewGuid().ToString();
return View("DocumentOpen", new List<string> { "in open event" });
}
Here is part of my View - I have many fields but I have created a view with only the upload widget:
@using Kendo.Mvc.UI
<form method="post" enctype="multipart/form-data">
<div class="k-content">
@(Html.Kendo().Upload()
.Name("attachments")
.Multiple(false)
.Async(async => async
.Save("UploadFileAsync", "Document", new { messageId = ViewBag.MessageId })
.Remove("RemoveFileAsync", "Document")
.AutoUpload(true)
)
)
</div>
</form>
Here the processing of the upload - as you can see the name and the parameter coincide (attachments) and the messageId has the GUID
[HttpPost]
public ActionResult UploadFileAsync(IEnumerable<HttpPostedFileBase> attachments, string messageId)
{
if (attachments == null) return Content("");
HttpPostedFileBase fileBase = attachments.FirstOrDefault();
var fileName = Path.GetFileName(fileBase?.FileName);
if (fileName != null)
{
var serverDirectory = System.Web.HttpContext.Current.Server.MapPath("~/" + messageId);
var serverPath = Path.Combine(serverDirectory, fileName);
fileBase.SaveAs(serverPath);
}
return Content("");
}
When running the code I get a GUID in the messageId field, the attachments field has a count of 0 i.e. It is *not* null. I have tried multiple examples here but am always getting the same error.
Any ideas?
PS: I cannot upload the project as it needs a backend document management system :(