Bonjour hi welcome to another video of cloud in five minutes I'm Frank Boucher
and today I'm answering your questions and show you how to unzip any file using
the azure functions in our previous video I show you how to unzip any file
using logic apps the connector used by logic app got a limit of hundred Meg's
for a file some of you asked me what can I do if my file is bigger than that so
today's demo is an answer for this problem
I will leverage as your functions that will get triggered when a new file is
created in the blob storage and it will unzip it in another blob storage so
let's get started so today I'm running on a Windows machine and I'm using
Visual Studio code of course you can run that in Mac OS or Linux also in vs code
I will be leveraging the extension as your functions that you can find so if
you go in the extension icon menu here you will find the azure functions
extension you click on that and now you have a new section functions so first we
need to create a function app or a project so let's create that one is the
first icon and I will call it unzip everything you have multiple options for
the language I will use C sharp perfect now the project is created so now let's
go back to the azure extension and we'll create here the second icon the little
lightning with the plus create a function so we first select the project
and then for today's demo I'm creating a blob trigger and then we provide a name
so I will call it unzip this and I need to provide a name space now we need to
put some app settings so I will just create a new account storage and
resource group and the location now azure is creating
our resources and should get back to us very soon and voila
asking us the name of the container that we are looking at so I will be looking
in input files well everything is created I have some code prepare for you
I will just paste it and then I will walk you through so we have a source
defined in our blog trigger I needed a way to define the destination so I will
put some settings in the configuration file so I'm using the environment here
too to set it up so I will need to add a destination storage and a destination
container also in my settings then I take the name I check if it's a zip file
because my code right now is only supporting that so you guys if you're
looking for solution for R or 7-zip or gzip or something like that
you will need to use another library and talking about library I'm using here the
new system IO compression and that one is perfect for zip so we'll be using
that so what I do here is I use the stream that I received from my trigger
and I'll create an archive and then I'm using the well-known
storage call where I create a reference to my first storage account and then my
blob and then my container you could be thinking but Frank well you could have a
binding in and a binding out and you're right but because when you are unzipping
files there are many changes that you have one entry and multiple out so
because of that it's kind of a dynamic out and it won't work so that's why we
are using here the usual code so then if I scroll up a little for every entry in
my archive I will be creating my blob and uploading it very simple ok so let's
save this if we go back in the azure extension I have here the third option
as little arrow pointing to the sky I need to deploy my function so let's do
this so first we need to select our
subscription so we'll create a new one we'll call it Asher unzip everything
then I will use my resource group it will be a best practice to separate your
code from your data but because it's a demo we'll put everything in one
resource group same thing for the storage so now other resources are
created in Azure then our code will be compiled and finally we'll everything
will be deploying perfect so now everything has been deployed and one
nice feature of the extension is you could right click here on application
sitting and had new settings right away so just like this and I will do the same
for all the other settings voila now all our settings are in there
so another nice feature is we could start streaming the logs so the function
is running in Azure we could get the log and see them in vs code very useful for
debugging so let's start that and while it's connecting let's go create the
containers in our blob storage so we'll go in Azure and then in resource called
five minutes here I have my storage account so let's go in the blobs so I'll
create my output containers and I will also need to create my input container
so okay perfect so now what I need to do is go in our input we are ready to test
it and it will upload a file so I add the file here that is 165 Meg's so
larger than 100 I will use that as a test so upload it so now what we could
expect is when this file will be done uploading it will trigger the functions
that will unzip the file and put everything in the output containers and
we should see a trace in our visual studio code Hey wow we see a lot so
file Oh one that zip has been triggered and then we see all the file press
one-by-one unzip it and if I go back in my if I double-click here and I go in my
output container here I have all the file so you could be using it directly
binding on your blood storage you could have a logic app calling it or you could
have an automation that runs every morning or once a week calling that
function two-zip how is unzipping which you could
clearly zipping a backup or something and having that in a next video I will
show you how to package this to deploy automatically in a CI CD until then here
another video of clouds and fibers see you too see you soon bye
you