【问题标题】:Store json object to Azure blob storage将 json 对象存储到 Azure Blob 存储
【发布时间】:2019-04-18 20:19:36
【问题描述】:

有什么方法可以存储 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")
}));

有没有更好的办法?

【问题讨论】:

    标签: node.js azure azure-storage azure-blob-storage


    【解决方案1】:

    当然,您可以像这样使用createblockblobfromtext 发送文本:

    blobService.createBlockBlobFromText(
        'container', 
        'something.json',
        JSON.stringify(msg) 
        option, 
        function onResponse(error, result) {
            console.log("done")
        });
    

    【讨论】:

      猜你喜欢
      • 2014-08-05
      • 2016-04-30
      • 2021-03-19
      • 1970-01-01
      • 2018-01-11
      • 2020-08-25
      • 2017-02-20
      • 2019-05-01
      • 2017-04-18
      相关资源
      最近更新 更多