Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript azure BlobsService createBlockBlobFromStream的js阵列到流_Javascript_Azure_Stream_Azure Storage Blobs - Fatal编程技术网

Javascript azure BlobsService createBlockBlobFromStream的js阵列到流

Javascript azure BlobsService createBlockBlobFromStream的js阵列到流,javascript,azure,stream,azure-storage-blobs,Javascript,Azure,Stream,Azure Storage Blobs,我有一个数组,我想使用createBlockBlobFromStream将内容上传到azure 示例代码: var myStream = getSomeStream(); var myStreamLength = getSomeStreamLength(); blobService.createBlockBlobFromStream( containerName, 'my-awesome-stream-blob', myStream, myStreamLength

我有一个数组,我想使用createBlockBlobFromStream将内容上传到azure

示例代码:

var myStream = getSomeStream();
var myStreamLength = getSomeStreamLength();
blobService.createBlockBlobFromStream(
    containerName,
    'my-awesome-stream-blob',
    myStream,
    myStreamLength,
    function(error, result, response){
        if(error){
            console.log("Couldn't upload stream");
            console.error(error);
        } else {
            console.log('Stream uploaded successfully');
        }
    });

但是,我不知道如何从数组中生成myStream和myStreamLength。

您可能需要使用函数,该函数可能更容易将流上载到Azure存储。您不再需要担心那里的流长度。然后,您可以使用以下代码从数组生成流

var fs = require('fs');
var azure = require('azure-storage');
var Readable = require('stream').Readable;

var accountName = "youraccountname";
var accessKey = "youraccountkey";
var host = "https://yourhost.blob.core.windows.net";
var blobSvc = azure.createBlobService(accountName, accessKey, host);

var myArray = ["Saab", "Volvo", "BMW", 788, 12.3];

var rs = Readable();

for(item of myArray) {
    rs.push(String(item));
}
rs.push(null);  // indicates end-of-file basically - the end of the stream

rs.pipe(blobSvc.createWriteStreamToBlockBlob('mycontainer', 'mystream.txt'));

有关如何正确使用流的更多信息。

您可以做的一件事是将数组序列化为字符串(JSON.stringify(array)),然后使用createBlockBlobFromText上载该数组。这是一个可接受的解决方案吗?@GauravMantri不幸的是不是,因为数据超过了FromText函数的64MB限制