当使用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);
});
});

——结果——

Upload Complete3 (%): 100.00

总:4.61 kb


我想实时获取下载进度

但它只在连接完成后出现一次。

我怎么做??

Storage clients have a default limit of 32 MB maximum size for a single block upload。当块blob上传大于' SingleBlobUploadThresholdInBytes '中的值时性质,storage clients break the file into blocks of maximum allowed size and try to upload it。由于您尝试上传的块blob大小可能大于32 MB,因此会抛出异常并将文件分解为允许的较小块,因此上传进度条在此之前不会跟踪上传blob的进度,并且会卡住. 因此,我建议您可以尝试设置' SingleBlobUploadThresholdInBytes '属性捕获'网络包'调用' UploadFromByteArray '方法查找详细错误时。

详情请参阅以下连结:-

将Azure blob块上传限制从32 MB增加

•另外,请参考下面的社区线程,该线程建议使用在progress类中注册的函数中使用公式来计算上传的总文件大小,使用下面的公式: -
(bytesUploadedSoFar/totalFileSizeInBytes)*100

Azure存储Blob下载进度指示器

最新更新