node.js - Azure Functions: How to read blob input for nodejs? -
i have setup azure function triggered blob being added specific container. blob .zip file intention use adm-zip
extract blob directory , read contents. confused the documentation here: https://github.com/azure/azure-content/blob/master/articles/azure-functions/functions-bindings-storage.md#blob-trigger-supported-types says input parameter can either object or string. don't see place in function.json specify want input be.
in code below, type seems string, since doesn't print assume it's buffer of bytes representing file contents. in order work this, i tried write buffer local file, not successful. did not throw error or print out saved blob to...
in function.json have this:
{ "bindings": [ { "name": "xmlzipblob", "type": "blobtrigger", "direction": "in", "path": "balancedataxml", "connection": "sc2iq_storage" } ], "disabled": false }
and have xmlzipblob
second argument function:
var fs = require('fs'); module.exports = function (context, xmlzipblob) { context.log('node.js blob trigger function processed blob:', xmlzipblob); context.log(`typeof xmlzipblob:`, typeof xmlzipblob); fs.writefile('xmlzip.zip', xmlzipblob, (err) => { if (err) { throw err; } context.log('saved blob loal file called xmlzip.zip'); context.done(); }); };
1. type of input paramater function blobs?
2. how control whether input parameter object or string?
3. possible use native node fs
module write local file system extracting .zip file?
update: believe failing due attempting use file system , have opened separate more isolated question here: azure functions: nodejs, restrictions / limitations when using file system?
4. there better alternative using .zip files?
until solved, think have come different solution dealing .zip file. either doing in memory streams, or avoiding .zip files , building larger xml file out of smaller xml files. either way, seems there should documentation or warning on take port node function depends on file system azure functions.
in node functions (as opposed c# declare parameter type in function definition) input type defaults string. if you're trying bind binary data, can indicate in function.json binding via datatype property, e.g.:
{ "bindings": [ { "name": "xmlzipblob", "type": "blobtrigger", "datatype": "binary", "direction": "in", "path": "balancedataxml", "connection": "sc2iq_storage" } ] }
this pass blob input function node buffer. note not streaming - buffer read entirely memory.
regarding question on file system access, answered question on other post :)
Comments
Post a Comment