简体   繁体   English

KendoUpload - 在上传或运行时更改块大小

[英]KendoUpload - Change chunksize during upload or at runtime

I am using Kendo Upload for the chunk upload.我正在使用 Kendo Upload 进行块上传。

//On Initialization
 $("#folders").kendoUpload({
                    async: {
                        saveUrl: baseAddrs + "/" + "DragAndDrop/ChunkSave",
                        removeUrl: baseAddrs + "/" + "DragAndDrop/remove",
                        chunkSize: 100000000, //~ 95MB
                        autoUpload: true,
                        concurrent: true

                    },
                    upload: onUpload,
                    directory: true,
                    directoryDrop: true,
                    complete: onComplete,
                    success: onFileSuccess,
                    error: onError
                });

I want to change the chunksize value on upload as below but it is not happening: How i can change this value :我想更改上传时的块大小值,如下所示,但没有发生:我如何更改此值:

 function onUpload(e) { 
                    //File Count                   
                    var fileCount = this.wrapper.find(".k-file").length;
                    e.sender._module.metaData[e.files[0].uid].EntityID=entityID;
                    e.sender._module.metaData[e.files[0].uid].EntityType=docSrcType;
                    e.sender._module.metaData[e.files[0].uid].SelectedFolder=selectedFolder;
                    e.sender._module.metaData[e.files[0].uid].Key = entityID; 
                    e.sender._module.metaData[e.files[0].uid].uploadedFileCount = fileCount;
                    if (bChunkUploadFlag) 
                        e.sender.options.async.chunkSize = 10530000; // ~10MB    

      

You can update the properties of a widget by using the setOptions method.您可以使用setOptions方法更新小部件的属性。

Allows changing the widget configuration after initialization.允许在初始化后更改小部件配置。 Depending on the widget, some properties may not be changed, and the method's implementation varies for each widget.根据小部件的不同,某些属性可能不会更改,并且每个小部件的方法实现都不同。

var upload = $("#folders").data("kendoUpload");
console.log(upload.options.async.chunkSize);

upload.setOptions({
    async: {
        chunkSize: 10530000
    }
});

console.log(upload.options.async.chunkSize);

However, there are some things to consider when using setOptions as detailed in the documentation:但是,在使用文档中详述的setOptions时需要考虑一些事项:

In some cases, the setOptions method can recreate and rebind the widget instance.在某些情况下, setOptions 方法可以重新创建和重新绑定小部件实例。 Calling setOptions in an event handler or the respective widget is not recommended and can cause an endless loop or a JavaScript error.不建议在事件处理程序或相应的小部件中调用 setOptions,这可能会导致无限循环或 JavaScript 错误。

I haven't had any successful uploads when calling setOptions in the onUpload event ( dojo ).onUpload事件 ( dojo ) 中调用setOptions时,我没有任何成功上传。

Using setOptions outside of the event has worked though ( dojo ).在事件之外使用setOptions已经奏效( dojo )。

I believe this answers you're question on how to change the value.我相信这可以回答您关于如何更改值的问题。 Getting the value changed at the moment you want it to and the uploader still work, may take some rethinking.在您想要的那一刻更改值并且上传器仍然有效,可能需要重新考虑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM