<SfUploader ID="UploadFiles1" AutoUpload="false">
<UploaderEvents OnFailured="onFailure"></UploaderEvents>
<UploaderAsyncSettings SaveUrl="https://aspnetmvc.syncfusion.com/services/api/uploadbox/Save" RemoveUrl="https://aspnetmvc.syncfusion.com/services/api/uploadbox/Remove"></UploaderAsyncSettings>
</SfUploader>
@code{
private void onFailure(FailureEventArgs args)
{
args.StatusText = "Failed";
}
} |
|
Really looking forward to a resolution for this also.
Have a great day!
[HttpPost("[action]")]
public void Save(IList<IFormFile> chunkFile, IList<IFormFile> UploadFiles)
{
long size = 0;
try
{
foreach (var file in UploadFiles)
{
var filename = ContentDispositionHeaderValue
.Parse(file.ContentDisposition)
.FileName
.Trim('"');
var folders = filename.Split('/');
var uploaderFilePath = hostingEnv.ContentRootPath;
// for Directory upload
if (folders.Length > 1)
{
for (var i = 0; i < folders.Length - 1; i++)
{
var newFolder = uploaderFilePath + $@"\{folders[i]}";
Directory.CreateDirectory(newFolder);
uploaderFilePath = newFolder;
filename = folders[i + 1];
}
}
filename = uploaderFilePath + $@"\{filename}";
size += file.Length;
if (!System.IO.File.Exists(filename))
{
using (FileStream fs = System.IO.File.Create(filename))
{
file.CopyTo(fs);
fs.Flush();
}
}
}
}
catch (Exception e)
{
Response.Clear();
Response.StatusCode = 404;
Response.HttpContext.Features.Get<IHttpResponseFeature>().ReasonPhrase = "File failed to upload";
Response.HttpContext.Features.Get<IHttpResponseFeature>().ReasonPhrase = e.Message;
}
Response.Headers.Add("status", "File failed");
} |
public void OnSuccess(Syncfusion.Blazor.Inputs.SuccessEventArgs args)
{
var customHeader = new string[] { };
customHeader = args.Response.Headers.Split(new Char[] { '\n' }); // To split the response header values
for (var i =0; i< customHeader.Length; i++)
{
if(customHeader[i].Split(new Char[] { ':' })[0] == "status")
{
key = customHeader[i].Split(new Char[] { ':' })[0]; // To get the key pair of provided custom data in header
value = customHeader[i].Split(new Char[] { ':' })[1].Trim(); // To get the value for the key pair of provided custom data in header
}
}
} |
@Michael pretty much hit the nail on the head... given your example code I see I wasn't the only one who assumed that the error would be reported to the client. Worse yet, I didn't come to this understanding until I had already published to production and had actual unreported upload failures that all gave a "Success" status! I highly suggest changing the demo to avoid confusion to others.
Hi Anthony,
Thank you for your suggestion. We appreciate your feedback and will take it into consideration as we work to improve our documentation. We will make sure to update our sample and inform you when the updated documentation is published. Thank you for taking the time to reach out to us.
Regards,
Sureshkumar P