Naf*_*lam 3 azure azure-storage azure-storage-blobs node.js
有什么方法可以存储 json 对象而不将其转换为流?我可以在将其转换为流后上传。但是有没有将对象存储为 {something}.json 而不将其转换为流的方法?
我现在应该做什么
const azureStorage = require('azure-storage');
const blobService = azureStorage.createBlobService(accountName, accountKey);
var Readable = require('stream').Readable
var msg = {
a: "something",
b: "anotherthing"
}
var stream = new Readable
stream.push(JSON.stringify(msg))
stream.push(null)
var option = {
contentSettings: {contentType: 'application/json'}
}
stream.pipe(blobService.createWriteStreamToBlockBlob('container', 'something.json', option, function onResponse(error, result) {
console.log("done")
}));
Run Code Online (Sandbox Code Playgroud)
有没有更好的办法?
当然,您可以像这样使用createblockblobfromtext发送文本:
blobService.createBlockBlobFromText(
'container',
'something.json',
JSON.stringify(msg)
option,
function onResponse(error, result) {
console.log("done")
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5826 次 |
| 最近记录: |