use*_*126 4 stream azure node.js
我正在尝试使用azure-storage上传流,但该方法CreateBlockBlobFromStream需要流长度.我不知道在哪里长度.
我的代码
const Readable = require('stream').Readable;
const rs = Readable();
rs._read = () => {
//here I read a file, loop through the lines and then generate some xml
};
const blobSvc = azure.createBlobService(storageName, key);
blobSvc.createBlockBlobFromStream ('data','test.xml', rs, ???, (err, r, resp) => {});
Run Code Online (Sandbox Code Playgroud)
而不是createBlockBlobFromStream尝试使用createWriteStreamToBlockBlob.
以下代码示例将字母az压入myblob.txt.
var azure = require('azure-storage');
const Readable = require('stream').Readable;
const rs = Readable();
var c = 97;
rs._read = () => {
rs.push(String.fromCharCode(c++));
if (c > 'z'.charCodeAt(0)) rs.push(null);
};
var accountName = "youraccountname";
var accessKey = "youraccountkey";
var host = "https://yourhost.blob.core.windows.net";
var blobSvc = azure.createBlobService(accountName, accessKey, host);
rs.pipe(blobSvc.createWriteStreamToBlockBlob('mycontainer', 'myblob.txt'));
Run Code Online (Sandbox Code Playgroud)
如果要读取具有可读流的文件,代码将如下所示:
var fs = require("fs");
// ...
var stream = fs.createReadStream('test.xml');
stream.pipe(blobSvc.createWriteStreamToBlockBlob('mycontainer', 'test.xml'));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6410 次 |
| 最近记录: |