简体   繁体   中英

Get Blob Content from bindings and then zip the content and save it in the blob container using azure function

I am using bindings of azure function to get the blob content and to store the file in blob. Below is the code that I am using but its not passing anything to the output bindings.

const JSZip = require("jszip");
const saveas = require('file-saver')
module.exports = async function (context, myBlob) {
    context.log("Function Triggered. ", context.bindingData.blobTrigger);
        
 var input = context.bindings.myBlob;
     var inputBuffer = Buffer.from(input);
     var zip = new JSZip();
zip.file(inputBuffer);
zip.generateAsync({type:"blob"})
.then(function(content) {

 var j =   saveAs(content, "example.zip");
  context.bindings.myOutputBlob = j; 
});
 
 
 
 }

Please let me know what I am doing wrong here.

You can setup the output binding in such a way to give a container name and a new blob name where you can input your content in it. And your code looks fine.

Also you can setup perfect bindings from VS Code just with few clicks according to your requirement.

Below is the sample input and output binding:

{
  "bindings": [
    {
      "queueName": "myqueue-items",
      "connection": "MyStorageConnectionAppSetting",
      "name": "myQueueItem",
      "type": "queueTrigger",
      "direction": "in"
    },
    {
      "name": "myInputBlob",
      "type": "blob",
      "path": "samples-workitems/{queueTrigger}",
      "connection": "MyStorageConnectionAppSetting",
      "direction": "in"
    },
    {
      "name": "myOutputBlob",
      "type": "blob",
      "path": "samples-workitems/{queueTrigger}-Copy",
      "connection": "MyStorageConnectionAppSetting",
      "direction": "out"
    }
  ],
  "disabled": false
}

Please refer to supported bindings

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM