是否可以仅下载追加 blob 的特定部分?



我将音频文件上传到我的 azure blob,我想知道是否可以只下载我想要的音频部分? 顺便说一句,我正在使用nodeJs
谢谢!

我将音频文件上传到我的 Azure blob,我想知道它是否 是否可以只下载我想要的音频部分?

是的,当然可以下载 blob 的一部分。Azure Blob 支持读取字节范围。例如,假设您只想从文件中下载前 1KB 的数据。以下是下载该数据的方式:

import azure from 'azure-storage';
const ms = require('memory-streams');
const chunkStart = 0;
const chunkEnd = 1023;
const connectionString = 'your-azure-storage-connection-string';
const blobService = azure.createBlobService(connectionString);
const writableStream = new ms.WritableStream({
highWaterMark: (chunk.end - chunk.start) * 2,
writableHighWaterMark: (chunk.end - chunk.start) * 2,
});
const requestOptions = {
rangeStart: chunkStart,
rangeEnd: chunkEnd
};
blobService.getBlobToStream('container-name', 'blob-name', writableStream, requestOptions, (error, result, response) => {
if (error) {
console.log('Error occurred while downloading chunk!');
} else {
const dataBuffer = writableStream.toBuffer();
console.log('Blob chunk downloaded!');
}
});

考虑到你提到要存储音频文件,请注意,你不能指示 Azure 存储下载"x"持续时间的音频(例如,下载前 30 秒的音频),因为 Azure 存储将所有 blob 视为字节集合,并且不知道该文件是音频文件还是其他内容。

最新更新