Telerik Forums
UI for ASP.NET Core Forum
0 answers
28 views

I'm attempting to use the Kendo Upload control asynchronously to an MVC controller, which passes the file to a WebApi controller.  The file is uploaded successfully, however when it returns to the MVC view, it reports that the file failed to upload with the error below.  We are using Azure B2C for authentication:

"Access to XMLHttpRequest at 'https... b2clogin.com...' (redirected from 'https//localhost:7074/Files/UploadFile') from origin 'https://localhost:7074' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource."

Server response:

"Failed to load resource: net::ERR_FAILED"

The control is located in a partial view as part of a tab control on a CSHTML view.  Here is the code for the upload control:

<div class="row">
    <div class="col-md-8">
        @(Html.Kendo().Upload()
                .Name("uploadedFile")
            .Multiple(false)
            .Validation(v =>
            {
                v.AllowedExtensions(new string[] { ".csv" });
                v.MaxFileSize(3145728);
            })
            .Async(a => a
                .AutoUpload(false)
                .Save("UploadFile", "Files")
            )
            .Events(e =>
            {
    e.Upload("onFileUpload");
            })

         )
    </div>
    <div class="col-md-4">
    </div>

</div>

Here is the C# code for the MVC controller:

        [HttpPost]
        public async Task<ActionResult> UploadFile(IFormFile uploadedFile, string month, string year)
        {
            if (uploadedFile == null || uploadedFile.Length == 0)
                return BadRequest("No file uploaded.");

            var reportingPeriod = month + year;

            using (var content = new MultipartFormDataContent())
            {
                if (uploadedFile.Length > 0)
                {
                    var streamContent = new StreamContent(uploadedFile.OpenReadStream());
                    streamContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(uploadedFile.ContentType);
                    content.Add(streamContent, "file", uploadedFile.FileName);
                }

                using (var response = await _client.HttpClient.PostAsync("/api/Files/loadbackdatedmonthlytrueupfile/" + reportingPeriod, content))
                {
                    if (response.IsSuccessStatusCode)
                    {
                        // Kendo expects an empty string for success
                        return Content("");
                    }
                    else
                    {
                        return StatusCode((int)response.StatusCode, await response.Content.ReadAsStringAsync());
                    }

                }

            }
        }

 

Here is the code for the WebApi controller:

[HttpPost("loadbackdatedmonthlytrueupfile/{reportingPeriod}")]
public async Task<IActionResult> LoadBackdatedMonthlyTrueUpFile([FromForm] IFormFile file, string reportingPeriod)

{

     //other logic here

     return Ok(new { file.FileName, file.Length });

}

This is the info I received from Copilot:

This error is caused by trying to call the Azure AD B2C /authorize endpoint using an XMLHttpRequest (AJAX/fetch) from your frontend (https://localhost:7074). Azure AD B2C does not support CORS for this endpoint, so the browser blocks the request.
Root cause:
The /authorize endpoint is designed for browser redirects, not AJAX/fetch/XHR.
No CORS headers will ever be present on this endpoint, so preflight requests will always fail.
How to fix:
Never use AJAX/fetch/XHR to call the /authorize endpoint.
Always use a full-page redirect for authentication.
For example, set window.location.href to the login URL, or let the [Authorize] attribute and OIDC middleware handle it for you.

How can I configure this upload control to return to the view without the error (attaching screenshot)?

Wendy
Top achievements
Rank 1
 asked on 17 Nov 2025
1 answer
22 views

Hi, I'm referring to the article below:

https://www.telerik.com/aspnet-core-ui/documentation/html-helpers/editors/upload/modes-of-operation#asynchronous-mode-fallback

In the article Asynchronous Mode Fallback is When Upload which is placed inside a form and configured for asynchronous operation.

I have done this, however after uploading some file (and failed since I didn't implement the controller) the form post still doesn't contain any Files.

Is there a specific to implement a fallback mechanism? a sample will be very helpful.

 

 

Ivaylo
Telerik team
 answered on 04 Aug 2025
0 answers
74 views
Is there a way to disable sending the token in the form? We would prefer to send it in the header.
Lenny
Top achievements
Rank 1
 asked on 23 Sep 2024
2 answers
330 views

Hello, I hope you are well.

I hope you can help me with this problem I have.

I am using the Kendo UI for JQuery Upload.

What I require is to upload an entire folder of TXT files, but I have a routine that validates that the name and content meet certain rules.

I apply these rules within the foreach loop (var file in files), because what is required is that if the file is valid it shows a text that it is valid, otherwise it shows a text that is not valid and for both options to continue processing the next file.

But by marking that file as erroneous, the controller is exited and the view is returned, thus leaving the processing of the rest of the files incomplete.

I share the code of the view and the controller, hoping you can give me some light.

View Code:

<div class="centered">
    @using Kendo.Mvc.UI
    <div>
        <div class="demo-section">
            @(Html.Kendo().Upload()
                .Name("files")
                .Async(a => a
                    .Save("ChunkSave", "Upload")
                    .Remove("Chunk_Upload_Remove", "Upload")
                    .AutoUpload(true)
                    .ChunkSize(11000)

                )
                .Multiple(true) // Enable multiple file selection
                    .Directory(true)
                    .DirectoryDrop(true)
                .Validation(validation =>
                {
                    //validation.MaxFileSize(20000000);
                })
                .Events(events =>
                {
                    events.Upload("onUpload");
                    events.Success("onUploadSuccess");
                    events.Error("onUploadError");
                    events.Select("onSelect");
                })
                .Messages(messages =>
                {
                    messages
                        .Select("Seleccionar archivos")
                        .DropFilesHere("Suelta archivos aquí para cargarlos")
                        .Remove("Eliminar")
                        .Retry("Reintentar")
                        .StatusFailed("Error")
                        .StatusUploaded("Terminado")
                        .StatusUploading("Cargando")
                        .UploadSelectedFiles("Cargar archivos")
                        .UploadFail("Error al procesar el archivo.")
                        .HeaderStatusUploaded("Terminado");
                })

            )
        </div>
    </div>
</div>

 

Controller Code:

public async Task<ActionResult> ChunkSave(IEnumerable<IFormFile> files, string metaData, string cve)
{

    int status = 0;
    DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(ChunkMetaData));


    MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(metaData));
    ChunkMetaData? somemetaData = serializer.ReadObject(ms) as ChunkMetaData;
    string path = String.Empty;

    if (files != null)
    {
        foreach (var file in files)
        {
            cap_dbt controller = new cap_dbt(_context);
            controller.ProcessFile(file, somemetaData.FileName, cve);
            status = controller.ProcessFile(file, somemetaData.FileName, cve);
            if (status == 1)
            {
                Upload(files, somemetaData.FileName);
            }
        }
    }


    if (somemetaData is null)
    {
        throw new Exception("No Metadata!");
    }

    Util.FileResult fileBlob = new Util.FileResult();
    fileBlob.uploaded = somemetaData.TotalChunks - 1 <= somemetaData.ChunkIndex;
    fileBlob.fileUid = somemetaData.UploadUid;
    fileBlob.warnings = Mensajes.msgLoadCsvWarning;
    fileBlob.message = "[" + somemetaData.FileName + "]\t";

    try
    {
        if (!fileBlob.uploaded)
        {
            fileBlob.message += "[ERROR]" + Mensajes.msgLoadCsvError;

            return StatusCode(500, fileBlob);
        }
        else if (status == -1)
        {
            fileBlob.uploaded = false;
            fileBlob.message += "[ERROR] " + Mensajes.msgLoadCsvError;
            throw new Exception(fileBlob.message); // <------- If I remove this line, it continues processing, but it no longer changes the file, it stays with the same name or empty.

        }

        if (fileBlob.warnings.Equals(""))
        {
            fileBlob.message += Mensajes.msgLoadCsvOk;
        }
    }

    catch (Exception ex)
    {
        Console.WriteLine(ex.ToString());
        return StatusCode(500, fileBlob);
    }
    finally
    {
        Mensajes.resetMsg();
    }

    return Json(fileBlob);
}

The following line was created to manipulate the Upload properties:
Util.FileResult fileBlob = new Util.FileResult();

I know what I can do if my file is not valid:
fileuid=""
success = false

But I see that if success is false it stops processing all the files and exits and goes to view.
Ashapura Softech
Top achievements
Rank 1
Iron
 answered on 29 May 2024
1 answer
291 views

Hello Telerik,

I am using the Kendo Upload Control with Async AutoUpload set to "true".  In version 2023.3.1114, when using "Select File" to upload a document the control works perfectly.  Dragging and dropping a file onto the control also works perfectly. 

After upgrading to 2024.1.130 using "Select File" to upload a document does not work, but dragging and dropping a file does work to upload a document.

Can you please advise me as to what I am doing wrong.  I am using jQuery v3.7.0.

My client side code looks like the following:
@(Html.Kendo().Upload()
		.Name("uplCtrl")
		.HtmlAttributes(new { aria_label = "files", title = "Select file to upload" })
		.Multiple(false)
		.Messages(m => m.Select("Select file...")
		.DropFilesHere("Drop file here to upload"))
		.ShowFileList(false)
		.Async(a => a
			.Save("UploadSave", "Vendors")
			.AutoUpload(true)                                        
		)
		.Validation(validation =>
		{
			validation.AllowedExtensions(new string[] { "pdf", "docx", "xlsx", "zip" });
			validation.MaxFileSize(52428800);
		})
		.Events(e => e
			.Error("onUploadError")
			.Complete("onUploadSuccess")
			.Upload("onUpload")
		)
	)

Ivan Danchev
Telerik team
 answered on 21 Mar 2024
1 answer
167 views

Razor code-behind method: I made the razor method as simple as possible, just to see if we could get in there / or hit onpostUploadFile
        public async Task<ActionResult> OnPostUploadFile(IEnumerable<IFormFile> files, string metaData)
        {
            AllowedExtensions = new string[] { "fpd", "pdf" };

            return Page();
        }

Razor page :

@addTagHelper *, Kendo.Mvc
<div>
    <div class="demo-section">
        <kendo-upload name="files">
            <async auto-upload="true" save-url="@Url.Action("Upload","UploadFile")" chunk-size="11000" />
            <validation max-file-size="20000000" />
        </kendo-upload>
    </div>
</div>

The issue is i am not able to hit the hander from the razor page when i pass the url to <async save-url="">, Despite many efforts, the handler specified in the save-url attribute doesn't seem to be hit and returns 404.

Not Working: 

1. save-url: "/Upload/UploadFile",

2. save-url="./Upload?handler=UploadFile"

I also found Forum where it discussed the same problem but that didn't help us :https://www.telerik.com/forums/upload-using-tag-helpers

 

Mihaela
Telerik team
 answered on 17 Jan 2024
1 answer
471 views

Hello!

I am trying to add a <kendo-upload> tag onto the toolbar of a kendo grid using TagHelper and ASP.NET Core

Though I am struggling with figuring out how to do this,  I have followed this template: https://demos.telerik.com/aspnet-core/grid/toolbar-template to not much success. 

My goal is to simply add a file upload option to upload an excel file to populate the fields of a grid!

Any ideas on how to progress?

Thank you!

But I am still struggling

Mihaela
Telerik team
 answered on 08 Dec 2023
1 answer
619 views

Hello,

 

where can I find the controller code for ASP.NET Core Upload Asynchronous Upload. Somehow when I trying to upload my file, I keep getting an error "failed to upload the file". below is what i have in my controller:

 


  public ActionResult Async_Save(IEnumerable<IFormFile> files)
        {
            // The Name of the Upload component is "files"
            string path = Path.Combine(_webHostEnvironment.WebRootPath, "FileSavePath");
            string DestinationPath = _configuration["DestinationPath"].ToString();
            if (files != null)
            {
                MoveFiles mf = new MoveFiles(); 
               
                foreach (var formFile in files)
                {
                    
                  

                    using (var stream = System.IO.File.Create(DestinationPath))
                    {
                        formFile.CopyTo(stream);
                    }

                    
                }
            }

This is my cshtml code:

 

any help will be apprecaited.
@using Kendo.Mvc.UI
<div style="margin-top:60px">
        <div class="block-section">
        @(Html.Kendo().Upload()
            .Name("files")
            .Async(a => a
                .Save("Async_Save", "Upload")
                .Remove("Async_Remove", "Upload")
                .AutoUpload(true)
            )
        )
    </div>
</div>

Vasko
Telerik team
 answered on 21 Aug 2023
1 answer
596 views
We are using Telerik for Asp.Net Core.  Using the file upload control in asynchronous chunk mode is there a maximum file size?  I know in synchronous mode its about 2gb, but I am curious if using chunk mode we can go past that since the file is uploaded in pieces.?
Vasko
Telerik team
 answered on 21 Aug 2023
1 answer
820 views
I have uploaded .wav audio file using kendo upload and i have the blob path and url, that the file is saved to.
Now do we have a control that helps us play audio file that is uploaded. like we have this
https://demos.telerik.com/aspnet-core/mediaplayer/events
Stoyan
Telerik team
 answered on 19 Jul 2023
Narrow your results
Selected tags
Tags
+? more
Top users last month
Edmond
Top achievements
Rank 1
Iron
fabrizio
Top achievements
Rank 2
Iron
Veteran
RobMarz
Top achievements
Rank 2
Iron
Fakhrul
Top achievements
Rank 1
Iron
Tejas
Top achievements
Rank 2
Iron
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Edmond
Top achievements
Rank 1
Iron
fabrizio
Top achievements
Rank 2
Iron
Veteran
RobMarz
Top achievements
Rank 2
Iron
Fakhrul
Top achievements
Rank 1
Iron
Tejas
Top achievements
Rank 2
Iron
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?