@{
var asyncSettings = new Syncfusion.EJ2.Inputs.UploaderAsyncSettings { SaveUrl = @Url.Content("~/Home/Save"), RemoveUrl = @Url.Content("~/Home/Remove") };
}
<div class="upload_Wrap">
<ejs-uploader id="UploadFiles" actionComplete="onActionComplete" success="onSuccess" asyncSettings="@asyncSettings"></ejs-uploader>
</div>
<img id="Pic" />
<script>
function onActionComplete(args) {
console(args.fileData[0].name);
document.getElementById("Pic").src = content + args.fileData[0].name;
}
(or)
function onSuccess(args) {
console(args.file.name);
document.getElementById("Pic").src = content + args.file.name;
}
</script> |
@{
var asyncSettings = new Syncfusion.EJ2.Inputs.UploaderAsyncSettings { SaveUrl = @Url.Content("~/Home/Save"), RemoveUrl = @Url.Content("~/Home/Remove") };
}
<div class="upload_Wrap">
<ejs-uploader id="UploadFiles" actionComplete="onActionComplete" asyncSettings="@asyncSettings"></ejs-uploader>
</div>
<img id="Pic" />
<script>
function onActionComplete(args) {
content = location.origin + location.pathname + '/../../';
console.log(args.fileData[0].name);
document.getElementById("Pic").src = content + args.fileData[0].name;
}
</script> |
[AcceptVerbs("Post")]
public IActionResult Save(IList<IFormFile> UploadFiles)
{
try
{
foreach (var file in UploadFiles)
{
if (UploadFiles != null)
{
var filename = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
filename = hostingEnv.WebRootPath + $@"{filename}";
if (!System.IO.File.Exists(filename))
{
using (FileStream fs = System.IO.File.Create(filename))
{
file.CopyTo(fs);
fs.Flush();
}
}
else
{
Response.Clear();
Response.StatusCode = 404;
Response.Headers.Add("status", "File Already Exists");
}
}
}
}
catch (Exception e)
{
Response.Clear();
Response.ContentType = "application/json; charset=utf-8";
Response.StatusCode = 400;
Response.Headers.Add("status", e.Message);
}
return Content("");
} |