0
votes

I am looking for a way to uploading files to Azure Blob Storage. I found azure-storage npm package. But I'm having a problem with 'createBlockBlobFromStream' method.

I dont know how create stream from 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);
                    }
                };

I`m trying to migarate files from S3 to Azure blob. Thats why I dowload files from S3, and than read it as ArrayBuffer and convert it to Uint8Array. And now I am looking way how to upload this data to azure via azure.createBlockBlobFromStream meyhod. Specifically, I need an example of creating a stream from Uint8Array.

I'll be grateful for any answer

1
I answered a similar question a few days ago - stackoverflow.com/questions/44952566/…. There I created a stream from Buffer. See if this helps you. - Gaurav Mantri

1 Answers

0
votes

In addition to an approach provided by Gaurav, once you created a stream from Uint8Array by using streamifier, you can use createWriteStreamToBlockBlob function to write to a block blob from a stream. With that you are able to transmit stream by calling .pipe():

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