I'm using a javascript library DropZone.js but uploading multiples files is somehow not working with ASP.Net MVC.
The one that works is when I set the Dropzone option "autoProcessQueue: true" and the MVC Controller argument name "inputFiles" can see the input files does successfully uploads to server. However, this means the uploading of images happens automatically and users has no chance to click the forms submit button. (I think that is why they call it DROPZone - auto uploads)
Anyways, I wanted to let users click the submit button before any uploads happens so I set the option "autoProcessQueue: false", but on form submit the argument name "inputFiles" at Controller always returns null.
<form action="/home" method="post" enctype="multipart/form-data" class="dropzone dz-clickable form-horizontal form-bordered" id="dropzoneForm">
<div class="form-group form-actions">
<div class="col-md-9 col-md-offset-4">
<button type="submit" class="btn btn-sm btn-primary"><i class="fa fa-floppy-o"></i> Upload</button>
</div>
</div>
</form>
<script>
$(function () {
Dropzone.options.dropzoneForm = {
paramName: "inputFiles", // The name that will be used to transfer the file
autoProcessQueue: true,
uploadMultiple: false,
parallelUploads: 100,
accept: function (file, done) {
done();
}
};
});
</script>
[HttpPost]
public ActionResult Index(IEnumerable<HttpPostedFileBase> inputFiles)
{
string fName = "";
foreach (HttpPostedFileBase fileName in inputFiles)
{
HttpPostedFileBase file = fileName;
//Save file content goes here
fName = file.FileName;
if (file != null && file.ContentLength > 0)
{
var originalDirectory = new DirectoryInfo(string.Format("{0}Images\\WallImages", Server.MapPath(@"\")));
string pathString = System.IO.Path.Combine(originalDirectory.ToString(), "imagepath");
var fileName1 = Path.GetFileName(file.FileName);
bool isExists = System.IO.Directory.Exists(pathString);
if (!isExists)
System.IO.Directory.CreateDirectory(pathString);
var path = string.Format("{0}\\{1}", pathString, file.FileName);
file.SaveAs(path);
}
}
return View();
}
Any one tried using DropZone.js?