I'm trying to set up an upload for some quite large files, which involves using chunked asynchronous uploads.
Once the file has been transferred, a record is saved to a database, with details of the file name, and an ID passed back to the web page.
I was able to get this working when the upload wasn't using chunks, but I'm now a bit stuck.
The example in your documentation (https://docs.telerik.com/aspnet-mvc/html-helpers/editors/upload/chunk-upload ) seems to be written for .later versions of the >NET framework (or .NET core), as I cannot find namespaces to include IFormFile or JsonSerializer . I'm using .NET Framework 4.7.2
I have got a version working (the file is saved to the upload folder), however, when the upload is complete, it does not call the Save procedure., which saves a record to a database, renames the file, and passes back a fileID.
The code is:-
public ActionResult ChunkSave(IEnumerable<HttpPostedFileBase> files, string metaData) { if (metaData == null) { return Save(files); } MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(metaData)); var serializer = new DataContractJsonSerializer(typeof(ChunkMetaData)); ChunkMetaData chunkData = serializer.ReadObject(ms) as ChunkMetaData; string path = String.Empty; string uploadFolder = SystemsPortal.Properties.Settings.Default.GLInterfaceUploadFolder; if (chunkData.chunkIndex == 0) { //1st chunk - check if file exists, and if so, delete before saving path = Path.Combine(uploadFolder, chunkData.fileName); if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } } path = String.Empty; // The Name of the Upload component is "files" if (files != null) { foreach (var file in files) { path = Path.Combine(uploadFolder, chunkData.fileName); AppendToFile(path, file.InputStream); } } Models.FileResult fileBlob = new Models.FileResult(); fileBlob.uploaded = chunkData.totalChunks - 1 <= chunkData.chunkIndex; fileBlob.fileUid = chunkData.uploadUid; return Json(fileBlob); }The control definition is:-
@(Html.Kendo().Upload().Name("files").Multiple(false).Events(e => e.Success("ulSuccess")).Async(a => a .Save("ChunkSave", "GLInterfaceUpload") .ChunkSize(250000) .AutoUpload(true)))
function ulSuccess(e) {
var response = e.XMLHttpRequest.responseText;
fileID = response;
alert(fileID);
e.sender.enable(false);
$('#divButton').show();
}
The Success event does fire, but the data returned, but as the Save procedure has never been called, no fileID is passed back.
How can I get this working as it should?
Thanks
