Welcome back. In this short video, we will understand how to write a file to file system. Again by using file module, let us see. So what I'll do is the same project I want to configure another flow. So right now what I want is I want a flow which will listen for HTTP requests. Okay?
So I'll drag and drop then in HTTP calls I'm expecting something like this. I'm expecting a URL like this a request with the word like this http colon slash slash localhost. 8081 slash right. I am expecting the request to come in this way. And then P ID product ID is equals to say one ampersand product name p name and set is a cause to say Samsung percent price is equals to 1000. So I'm expecting a request with three query parameters like this.
And what I want is by extracting these three query parameters, I want to write a file with name products dot CSV. With comma separated p IDP name and price. That's what I want to write. So firstly, I'll configure my HTTP listener exert one slash, right. Okay. Then I want to write a file.
So I'll go to File module again. There is an option to write. So I will drag and drop here. Again, if I double click on this right component, is asking me to select the connector, I will I will select the same file connector. What is that here is just the working directory cavitus SQL files. Okay.
And the path I will say is say output. So in my SQL files, there's a directory called us output and I want to right here and delete this existing one I want right? But what is the file name or the file name etc into contract. So, here when I use a path is the path of the file to it and not the directory So right here output slash se products dot c Yes, we want to write the payload of the mule message whatever the payload of the mule message I want to write it to CSV okay. So, what is the right mode here or right or up in I will say happened that ways if the file is already existing it will be appended. Then I configured the right operation to write whatever is the payload.
So, somehow I have to create a CSV record. What I will do is I'll just drag and drop the transform message component before write components so that I can create a CSV record. Now, if I double click here I want to define the output metadata. so here we can see in transform message section, there is one. In transform message properties. There is one section call us output, where I can click on this and define metadata.
I'll click on this. I'll click on Add. And I'll give a new type as my CSV, some name. And here, what are the type I want the output CSV. And if I have example, I can upload the example CSV. Or I won't define the fields.
So first column is p ID, I'll say product. underscore ID second, One is p name as a third one is price. Right now, two very simple, all of them be of type string only. Okay? So I defined output metadata and said that output will be CSV with all these columns. So I select Okay.
Now on the right side, you can see that metadata is straight, still resolving the metadata here. Yes, you saw that output metadata is an area of all this right. Now I'm expecting productivity productivity price from query parameters. So on the input, you can see the input metadata here you can see query parameters under attributes. So I want to map this query parameter. Just to write site, I'll drag and drop.
Actually product ID, it is mapped to attribute, query params. But the words the exact query parameter pages that I was expecting a request to come in is with the IDP name and price. So I modified product IDs mapper to query params dot p ID. And again, I'll drag and drop for name. I'll drag and drop for price. Here, I'll say query params dot p name.
And here I'll say dot rights. That's it. For this simple data expression. Don't worry about understanding this. I dragged and dropped and I configured them. So let me run now.
I stopped the existing running application. And then I'll run it again. Do you want to create the application? Now? I'll say no, I don't want to reprocess the file. Okay, the application started let me do let me first see output folder there is no file.
No, I'll give a request to slash write with all this sent. Okay. Yep, I got this as output, this output of my transformer. So should we return let them go to here and yeah, I can see product or CSV. If open the file is written with all this, great, right? So now you understood how to actually configure right component of file module, right operation of file module two, right.
And here, there are options like create were in directories. So if the output folder is not there, it'll automatically create if you select this, and I think you can easily understand what drive mode is append. If you want the file to be appended if it is already existing, create new will create a new file every time or overwrite. Try configured as append. That's why if I give a new request, the file content will be appended. Okay, so that's about how to write files using file module.
Now after this video, you can just open the lab documentation With the name 05 file module and there is step two, where I have given step by step instructions on what to do the same thing. Whatever I have done, you can just practice it by going through this document. So we are done with file module. I'll see you in next video.