第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

限制并發(fā)上傳

限制并發(fā)上傳

猛跑小豬 2022-05-22 10:11:38
我的 .NET Core 站點(diǎn)中有一個(gè)文件上傳系統(tǒng),允許用戶一次將任意數(shù)量的文件直接上傳到 S3 存儲(chǔ)桶。用戶可以上傳 1 個(gè)或多個(gè)文件。我遇到的問題是,當(dāng)上傳 1,000 個(gè)文件時(shí),瀏覽器不喜歡創(chuàng)建那么多連接,而且文件通常無法上傳。即使啟用了重試,這些重試也往往會(huì)失敗,因?yàn)闉g覽器只允許一定數(shù)量的并發(fā)連接。更糟糕的是,瀏覽器會(huì)鎖定。我要做的是將文件放入隊(duì)列中,并且在任何給定時(shí)間僅允許實(shí)際上傳 20 個(gè)文件(想想 FileZilla 如何將要上傳的項(xiàng)目排隊(duì))。當(dāng)一個(gè)文件完成時(shí),會(huì)添加一個(gè)新文件,直到隊(duì)列用完。這樣瀏覽器只會(huì)創(chuàng)建它需要的連接。我已經(jīng)有了它,所以AutoUpload設(shè)置為False,我可以將文件放入一個(gè)數(shù)組中進(jìn)行處理,但該uploadSelectEvent.sender.upload()方法可以上傳所有內(nèi)容。有沒有辦法在啟用上傳之前暫停所有上傳,以便我可以根據(jù)需要恢復(fù)它們?有沒有更好的方法來處理這個(gè)?
查看完整描述

1 回答

?
拉風(fēng)的咖菲貓

TA貢獻(xiàn)1995條經(jīng)驗(yàn) 獲得超2個(gè)贊

我能夠自己解決這個(gè)問題。以下是方法(請(qǐng)注意,這需要一些修改才能適用于您自己的代碼,我不是純粹的復(fù)制和粘貼答案):


創(chuàng)建一個(gè)數(shù)組來保存一些數(shù)據(jù):


/** Files currently uploading */

const uploadQueue: any[] = [];

捕獲FileSuccess事件并添加它


    // Check the size of the queue

    if (uploadQueue.length < 20) {

        const that = (uploadSuccessEvent.sender as any);

        const module = that._module;

        const upload = module.upload;


        $(".k-file").each((i, x) => {

            //console.log(i, x);

            if (uploadQueue.length < 20) {

                const fileEntry = $(x);

                const started = fileEntry.is(".k-file-progress, .k-file-success, .k-file-error");

                const hasValidationErrors = upload._filesContainValidationErrors(fileEntry.data("fileNames"));


                if (!started && !hasValidationErrors) {

                    uploadQueue.push(fileEntry.data("fileNames")[0].uid);

                    //console.log("fileEntry", fileEntry.data("fileNames")[0].uid);


                    // Start the upload process

                    module.performUpload(fileEntry);

                }

            }

            else { return; }

        });

    }

創(chuàng)建一個(gè)新函數(shù)來處理上傳隊(duì)列:


/**

 * Adds the file to the upload queue and starts the upload.

 * Other files will be loaded via the on success event.

 * @param uploadSelectEvent Select event object.

 */

function queueUpload(uploadSelectEvent: kendo.ui.UploadSelectEvent) {

    //console.log("uploadSelectEvent", uploadSelectEvent);


    // Check the size of the queue

    if (uploadQueue.length < 20) {

        // Start the upload process

        const that = (uploadSelectEvent.sender as any);

        const module = that._module;

        const upload = module.upload;


        //uploadSelectEvent.files.forEach((file, i) => { console.log(i, file); if (uploadQueue.length < 20) { uploadQueue.push(file.uid); } });


        $(".k-file").each((i, x) => {

            //console.log(i, x);

            if (uploadQueue.length < 20) {

                const fileEntry = $(x);

                const started = fileEntry.is(".k-file-progress, .k-file-success, .k-file-error");

                const hasValidationErrors = upload._filesContainValidationErrors(fileEntry.data("fileNames"));


                if (!started && !hasValidationErrors) {

                    uploadQueue.push(fileEntry.data("fileNames")[0].uid);

                    module.performUpload(fileEntry);

                }

            }

            else { return; }

        });

    }

}

捕獲FileSelect事件并將事件傳遞給queueUpload.


最后,您應(yīng)該一次將并發(fā)上傳限制為 20 個(gè)。它仍然允許將 100 個(gè)或 1000 個(gè)文件拖入瀏覽器(它可能仍會(huì)鎖定一秒鐘),但一次最多只能創(chuàng)建 20 個(gè)連接。這可能不是最理想的代碼,但它適用于我的情況。


查看完整回答
反對(duì) 回復(fù) 2022-05-22
  • 1 回答
  • 0 關(guān)注
  • 222 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)