【问题标题】:azure function triggers azure blob storageazure 函数触发 azure blob 存储
【发布时间】:2021-10-08 00:53:22
【问题描述】:

我需要在 nodejs 中编写一个 azure 函数,用于压缩上传到 azure blob 存储中的任何文件。 我有这段代码可以完成这项工作

const zlib = require('zlib');
const fs = require('fs');

const def = zlib.createDeflate();

input = fs.createReadStream('file.json')
output = fs.createWriteStream('file-def.json')

input.pipe(def).pipe(output)

the azure function

nodejs函数的定义是这样的

module.exports = async function (context, myBlob) {

其中 myBlob 包含文件的内容。

现在压缩使用流

如何将文件内容转换为流并将转换后的文件保存为上述脚本中的输出变量作为 blob 存储中的新文件但在另一个容器中?

谢谢

【问题讨论】:

    标签: azure-functions azure-blob-trigger


    【解决方案1】:

    JavaScript 和 Java 函数将整个 blob 加载到可以使用 context.bindings.Name 访问的内存中。 (其中 Name 是 function.json 文件中指定的输入绑定名称。)

    更多详情请查看Azure Blob storage trigger for Azure Functions

    由于字符串/内容已在内存中,因此无需使用流来处理zlib。下面的代码 sn-p 使用来自zlibdeflateSync 方法来执行压缩。

    var input = context.bindings.myBlob;
        
    var inputBuffer = Buffer.from(input);
    var deflatedOutput = zlib.deflateSync(inputBuffer);
    
    //the output can be then made available to output binding
    context.bindings.myOutputBlob = deflatedOutput;
    

    你可以参考链接here来讨论这个话题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-11
      • 2021-10-30
      • 2020-04-21
      • 1970-01-01
      相关资源
      最近更新 更多