【问题标题】:Meteor and Azure Blob storageMeteor 和 Azure Blob 存储
【发布时间】:2017-12-12 15:53:02
【问题描述】:

我正在寻找一种将文件上传到 Azure Blob 存储的方法。 我找到了azure-storage npm 包。 但我在使用 'createBlockBlobFromStream' 方法时遇到了问题。

我不知道如何从 Uint8Array 创建流。

 xhr.onload = function (e) {
                    if (this.status == 200) {

                        // Note: .response instead of .responseText
                        const blob = new Blob([this.response]);
                        console.log(audios[i].file);
                        const reader = new FileReader();

                        reader.onload = function () {
                            const data = new Uint8Array(reader.result);
                            Meteor.call('uploadFilesViaSDK', data);
                        };

                        reader.readAsArrayBuffer(blob);
                    }
                };

我正在尝试将文件从 S3 迁移到 Azure blob。这就是为什么我从 S3 下载文件,然后将其读取为 ArrayBuffer 并将其转换为 Uint8Array。 现在我正在寻找如何通过 azure.createBlockBlobFromStream meyhod 将此数据上传到 azure 的方法。 具体来说,我需要一个从 Uint8Array 创建流的示例。

如果有任何答案,我将不胜感激

【问题讨论】:

标签: node.js azure meteor azure-blob-storage node.js-stream


【解决方案1】:

除了 Gaurav 提供的方法之外,一旦您使用 streamifier 从 Uint8Array 创建了一个流,就可以使用 createWriteStreamToBlockBlob 函数从流中写入块 blob。这样您就可以通过调用.pipe() 来传输流:

streamifier.createReadStream(new Buffer(uint8)).pipe(blobSvc.createWriteStreamToBlockBlob('mycontainer', 'test.txt'));

【讨论】:

    猜你喜欢
    • 2016-06-16
    • 2016-09-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-10
    • 2012-03-02
    • 2016-03-04
    相关资源
    最近更新 更多