2016-12-22 4 views
3

azure-storageを使用してストリームをアップロードしようとしていますが、メソッドCreateBlockBlobFromStreamにストリーム長が必要です。私は長さをどこにするか分からない。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) => {}); 
+0

を持っていますか? –

+0

今日や外出中にこれを試してみましょう。私は休暇を過ごしていました:-) – user49126

答えて

6

createBlockBlobFromStreamの代わりにcreateWriteStreamToBlockBlobを試してみてください。

次のコード例は、a〜zの文字を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')); 

あなたが読めるストリームを持つファイルを読みたい場合は、コードは次のようになります。あなたはすべての更新を

var fs = require("fs"); 
// ... 
var stream = fs.createReadStream('test.xml'); 
stream.pipe(blobSvc.createWriteStreamToBlockBlob('mycontainer', 'test.xml')); 
+0

この機能はどのようにドキュメントにはありませんか? – user49126

+0

この関数のAPIリファレンスはhttp://azure.github.io/azure-storage-node/BlobService.html#createWriteStreamToBlockBlobにあります。 –

関連する問題