Kendo UI 块上传到 Microsoft Azure

Kendo UI chunk upload to Microsoft Azure

我正在为 ASP.Net 核心网站项目的附件上传功能实现块上传功能。目前文件上传由 Kendo UI 库处理,但当前实现不支持块上传。附件将上传到 Azure blob。

我已经按照图书馆给出的示例进行操作,但是我的 ASP.Net 控制器只收到上传文件的第一个块,没有收到块。

克林特一方:

    $("#xyzUpload").kendoUpload({
    async: {
        saveUrl: fileUploadUrl,
        chunkSize: 1048576,
        removeUrl: "remove",
        autoUpload: true
    },
    multiple: true,
    upload: function (e) {
        e.data = { id: $("#fileUplpderParentObjectId").val() };
    },
    showFileList: false,
    dropZone: ".abc",
    success: onSuccess
});

控制器操作:

 [HttpPost]
    public async Task<JsonResult> ChunkUpload(IEnumerable<IFormFile> files, string metaData, Guid id)
    {
        MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(metaData));

        JsonSerializer serializer = new JsonSerializer();
        ChunkMetaData chunkData;

        var userId = _userManager.GetUserId(User);
        var fileList = new List<GeneralFileViewModel>();

        using (StreamReader streamReader = new StreamReader(ms))
        {
            chunkData = (ChunkMetaData)serializer.Deserialize(streamReader, typeof(ChunkMetaData));
        }

        if (files != null)
        {
            foreach (var file in files)
            {
                var extension = Path.GetExtension(chunkData.FileName);
                var fileName = Path.GetFileNameWithoutExtension(chunkData.FileName);
                var guid = Guid.NewGuid();
                var generalFile = new GeneralFileViewModel()
                {
                    FileId = guid,
                    FileName = fileName,
                    Extension = extension,
                    //FileType = _jobsservice.GetFileType(extension),
                    ParentId = id
                };

                var blockId = Convert.ToBase64String(BitConverter.GetBytes(chunkData.ChunkIndex));

                //Write chunk to azure blob block
                await _uploadService.UploadInBlocksToAzure(blockId, generalFile, file.OpenReadStream());

                //if last chunk is uploaded, commit the blob into azure
                //await _uploadService.CommitBlocksToAzure();

                fileList.Add(generalFile);
            }
        }
        return Json(fileList);
    }

UploadInBlocksToAzure() 方法

public async Task UploadInBlocksToAzure(string id, GeneralFileViewModel file, Stream stream)
    {
        try
        {
            var storageAccount = CloudStorageAccount.Parse(_connectionString);
            CloudBlobClient cloudBlobClient = storageAccount.CreateCloudBlobClient();

            var container = cloudBlobClient.GetContainerReference("test-video-in");
            var blob = container.GetBlockBlobReference(file.FileId + file.Extension);
            await blob.PutBlockAsync(id, stream, null);
        }
        catch (Exception e)
        {
            throw;
        }
    }

代码没有抛出异常。

知道为什么 action 方法没有收到文件的其他块吗?

重要的是 return JSON 具有上传和 fileUid 属性的对象,它通知客户端下一个块应该是什么,如此处所述 - https://docs.telerik.com/kendo-ui/api/javascript/ui/upload/configuration/async.chunksize 您还可以在该演示中的 ChunkSave 方法中看到它是如何正常工作的 - https://demos.telerik.com/kendo-ui/upload/chunkupload