Video upload too big? Don’t panic slices uploaded to help you

First, the slicing method

Method 1 => web-worker

async calculateHash(chunks){
    return new Promise(resolve= > {
        // Prevent the main thread from stalling
        this.container.workder = new Worker("/hash.js");
        this.container.workder.postMessage({ chunks });
        // Complete the calculation callback
        this.container.workder.onmessage = e= > {
            const { progress, hash } = e.data;
            this.hashProgress = Number(progress.toFixed(2));
            if(hash) resolve(hash); }; })}Copy the code
// web-worker
that.importScripts('spark-md5.min.js')
that.onmessage = e= > {
    // Accept main thread notifications one at a time
    const { chunks } = e.data
    const spark = new that.SparkMD5.ArrayBuffer()
    let progress = 0
    let count = 0
    const loadNext = index= > {
        const reader = new FileReader()
        reader.readAsArrayBuffer(chunks[index].file)
        reader.onload = e= > {
            / / accumulator
            count++
            // Incrementally calculates MD5
            spark.append(e.target.Result)
            if (count === chunks.length) {
                // Tell the main thread that the calculation is complete
                that.postMessage({
                    progress: 100.hash: spark.end()
                })
            } else {
                // After each block is finished, the modification progress is notified
                progress += 100 / chunks.Length
                that.postMessage({
                    progress
                })
                // Calculate the next block
                loadNext(count)
            }
        }
    }
}
/ / start
loadNext(0)
Copy the code

Way 2 = >

Method three => Sampling hash to be continued