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
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'));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.