How to validate file content.

(Satish Kumar) #1

How to validate file content?

Can we validate the content before upload the file.


How to validate Xml content
(Yoga Ramya Mendu) #2

Hi @m.satish512,

You can validate the file extension by reviewing the “allowedFileTypes” array in chatwindow.js of webSDK.
This will make sure that only the file types mentioned in the array are uploaded.


Let us know if you need any further clarification on the above.

Yoga Ramya.

(Satish Kumar) #3

How can I validate only I can upload .txt file ?

EX : If I select .xml or .csv it will say please upload valid file.

How can I validate file content ?


(Yoga Ramya Mendu) #4

Hi @m.satish512,

As mentioned in our previous post, you will need to remove all the extensions that are available in the “allowedFileTypes” array in chatwindow.js of webSDK and have only .txt as per your requirement.

var allowedFileTypes = [".txt"];

You can find chatwindow.js in webSDK >> sdk >> UI >> chatwindow.js .

Yoga Ramya.

(Satish Kumar) #5

Thank you.!

How do we validation xml tree in script node?

I have to check whether xml is well. Formed or not.

Please reply on this ASAP.

Thank you!

(Yoga Ramya Mendu) #6

Hi @m.satish512,

As mentioned above, we can validate the file extensions through platform and WebSDK.
If you would like to parse through the uploaded file content and validate it, then you will need to write javascript as per your requirement.

Yoga Ramya.

(Satish Kumar) #7

Thanks for the reply.

But I’m facing issue while working with script node. I wrote a line of code ‘var parser = new DOMParser()’ ;

This line of code not executing in script node.

I was thinking, why DOMParser() works here?

Please provide some working solution with screen shots.

Thank you.

(Satish Kumar) #8

I’m validating files but if I upload invalid file multiple times its showing as valid file.
This is,y script node content :
if(context.Service0002.response.statusCode !== 200)
context.resultMsg = context.Service0002.response.body;
delete context.entities.Entity0001;
Please refer the below illustration.

(Subrahmanyam Donepudi) #9

DOMParser() is a browser thing and it is not supported at nodejs on which the platform is based on.
You could possibly try the below syntax to get the file extension at the script node though:

context.extType = context.entities.[i].fileName.slice((Math.max(0, context.entities.[i].fileName.lastIndexOf(".")) || Infinity) + 1)

Please refer to the below snips for more details:

(Satish Kumar) #10

Thanks for your reply :slight_smile:

My previous question was I couldn’t validate the content of the XML file if I upload invalid XML file for multiple times it is showing as valid at some point. Please refer my previous post.

Thank you!

(Satish Kumar) #11

I created two XML files one is valid one other is invalid, if I upload valid file and get uploaded content back thru Service node it is giving 200 as success code other hand if I upload invalid XML file it is also giving 200 as success code and it fails in some cases and it is giving “Unexpected close tag”
Line: 5
Column: 25
like this.

Could you please create two files and test those all the possible cases.

(Yoga Ramya Mendu) #12

Hi @m.satish512,

We understand your scenario, we will check and update you.

Yoga Ramya.

(Yoga Ramya Mendu) #13

Hi @m.satish512,

We observe from the above thread that you are validating the file content through the response status code from the service node by using the snippet:


Irrespective of the valid or invalid response received from the API, if we just have a response, then the status code would be 200 ok. If there is no response received at all, then we would be displaying an error that occurred while hitting the API.

With the above sentence, do you mean that for the same invalid file, the service node sometimes giving status code 200 and few other times giving error details?

Yoga Ramya.