Search code examples
javascriptnode.jsdownloadazure-blob-storageprogress-bar

Download percent come only one time when use Azureblob


async function getBackupTemplate(shipKey, historyLogBlobDirectory, reportDataBlobDirectory) {
    const historyLogStreamPath = `${window.remote.app.getPath('userData')}/backupStream1.txt`;
    const reportDataStreamPath = `${window.remote.app.getPath('userData')}/backupStream2.txt`;
    const historyLog = await new Promise((resolve, reject) => {
        const stream = fs.createWriteStream(historyLogStreamPath);
        let historySummary = window.blobService.getBlobToStream(window.containerName, historyLogBlobDirectory, stream, async (err, text) => {
            console.log(historyLogStreamPath)
            console.log('historySummary1', historySummary)

            if (err) {
                if (err.statusCode === 403) {
                    azureCustomService.setRequestDateHeaderFromAzureServerTimeStamp(err.message);

                    await azureCustomService.communicateAzureWithCustomHeader('GET', window.containerName, historyLogBlobDirectory);
                    try {
                        azureCustomService.streamParsingToJSON(historyLogStreamPath, (err, data) => {
                            resolve(JSON.parse(data));
                        });
                    } catch (e) {
                        reject(e);
                    }
                }
            } else {                  
                console.log('comp history', text)
                azureCustomService.streamParsingToJSON(historyLogStreamPath, (err, data) => {
                    resolve(JSON.parse(data));
                });
            }
        });
        console.log('historySummary2', historySummary)

        historySummary.on('progress', function() {
            var percentComplete = historySummary.getCompletePercent(2);
            var totalSize = historySummary.getTotalSize(true);
            console.log('Upload Complete3' + percentComplete);
            console.log('total: ' + totalSize);
        });
    });

----result----

Upload Complete3 (%): 100.00

total: 4.61KB


I want get download progress realtime

but it coming only one time after connection complete.

How can I make ??


Solution

  • Storage clients have a default limit of 32 MB maximum size for a single block upload. When a block blob upload is larger than the value in ‘SingleBlobUploadThresholdInBytes’ property, storage clients break the file into blocks of maximum allowed size and try to upload it. Since the block blob size that you are trying to upload might be greater than 32 MB, it throws an exception and breaks the file into allowed smaller chunks due to which the upload progress bar doesn’t track the progress of blobs uploaded until that point and gets stuck. Thus, I would suggest you could try to set the ‘SingleBlobUploadThresholdInBytes’ property or capture the ‘Network Package’ when you invoke the ‘UploadFromByteArray’ method to find the detailed error.

    For more details, kindly refer to the link below: -

    Increase Azure blob block upload limit from 32 MB

    • Also, kindly refer to the below community thread which suggests a workaround by using a formula in the function that is registered with the progress class to calculate the total file size uploaded by using the below formula: -

      (bytesUploadedSoFar/totalFileSizeInBytes)*100
    

    Azure Storage Blob Download Progress Indicator