Kendo UI块上传到Microsoft Azure

问题描述 投票:0回答:1

我正在为ASP.Net Core网站项目的附件上传功能实现块上传功能。目前,文件上传由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;
        }
    }

代码中没有抛出异常。

有什么想法为什么动作方法不接收文件的其他块?

asp.net ajax azure asp.net-core kendo-asp.net-mvc
1个回答
1
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.