我正在使用axios
从Azure存储Blob下载文件(〜100MB)。
axios({
method: 'get',
url: uri,
onDownloadProgress: (progressEvent) => {
console.log("Loaded: " + ((progressEvent.loaded / progressEvent.total) * 100) + "%");
},
responseType: 'arraybuffer'
}).then({})
我的问题是实际下载文件要花费相当长的时间(约10分钟)。我以前使用的是fetch(),它甚至比这还要慢(〜15-20分钟)。你们对加快下载速度有什么建议吗?我的网速不是问题,因为直接下载文件或使用Azure Storage Explorer(1.12.0,AzCopy 10.3.3)只需不到2分钟的时间。
我还尝试使用azure-storage的blobServiceClient,但速度与axios和fetch差不多(大约15kbps)。
这可以在React应用程序中提供。
答案 0 :(得分:2)
我已经测试了下载速度。希望我的结果对您有用。
- 我将
StorageExplorer.exe
作为源文件上传进行下载测试。文件大小为92.5M。
- 通过
Azure Storage Explore
下载文件,将花费1 minute and 07 seconds
。
- 通过chrome浏览器在门户网站中下载文件,将花费
58 seconds
。
- 通过我的测试代码下载文件。
①从portal
或Storage Explore
复制网址。
网址类似:https://p*****ge.blob.core.windows.net/testcontainer/StorageExplorer.exe
根据我的代码进行测试后,它将花费1 minute and 52 seconds
,并且非常不稳定,有时测试下载时间会更长。
②从AzCopy Command
复制网址。
URL格式如下:https://pan********ge.blob.core.windows.net/testcontainer/StorageExplorer.exe?se=2020-09-18T07%3A55%3A28Z&sp=rl&sv=2018-03-28&sr=c&sig=5kJyTBwHHRS******mlj3%2FWj9CmvQriXCMi4%3D
经过相同代码的测试后,将花费1 minute and 02 seconds
。
我的测试结论:
请勿使用看起来像https://p*****ge.blob.core.windows.net/testcontainer/StorageExplorer.exe
的网址。
您可以使用类似于从AzCopy命令获取的网址。
下面是我的测试代码。
- 我进步了
- npm i axios
'use strict'
const Fs = require('fs')
const Path = require('path')
const Axios = require('axios')
const ProgressBar = require('progress')
async function download () {
const url = 'https://pan*****e.blob.core.windows.net/testcontainer/StorageExplorer.exe'
console.log('Connecting …')
const { data, headers } = await Axios({
url,
method: 'GET',
responseType: 'stream'
})
const totalLength = headers['content-length']
console.log('Starting download')
const progressBar = new ProgressBar('-> downloading [:bar] :percent :etas', {
width: 40,
complete: '=',
incomplete: ' ',
renderThrottle: 1,
total: parseInt(totalLength)
})
const writer = Fs.createWriteStream(
Path.resolve(__dirname, 'software', 'StorageExplorer.exe')
)
data.on('data', (chunk) => progressBar.tick(chunk.length))
data.pipe(writer)
}
download()