18 January 2026:
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
This forum is now archived and is in read-only mode. Please continue discussions on our improved new Sahi Pro Community forum.
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
How to return the size of a file
Is there any way to return the file size (in KB or MB or even bytes) of a file stored in a local drive?
Regards,
Anoop
Regards,
Anoop
This discussion has been closed.
Comments
Since Sahi is based upon javascript, there is no direct method to return the file size of a file stored in a local drive. Usually the file size validation in done on the server side.
You can go through the following link,
http://4umi.com/web/javascript/fileread.php
This might help you.
If you require to perform the validation of file size during file uploading, You can test with
in Evaluate Expression textbox and It will alert with the size of file in bytes.
This does'nt work during playback, since file upload validation is done with some sort of workaround.
Regards,
Theeran.
the log file shows error as showed me error
_setValue(_textbox("username"), _file("C:\\sahi\\userdata\\scripts\\test3mb.pdf").files[0].size);
TypeError: _sahi._file("C:\\sahi\\userdata\\scripts\\test3mb.pdf.pdf") is undefined
Actually i want to validate the alert message if file size is above 2MB as it doesn't allow upload above 2MB. For that i need to get the file size and compare using if statement.
Is there any solution?
Regards,
Anoop
Regards,
Anoop
Try with the following script,
This script will alert with the size of file being uploaded in bytes.
Regards,
Theeran.
var $fileSize = new java.io.File("C:\\sahi\\userdata\\scripts\\test3mb.pdf").length();
and then use $fileSize.
Having said that, since you are the person who has created that static file, you can as well hardcode the size of the file in your testcase.
Regards,
Narayan
Both solutions work great! (with some difference between the number of bytes returned by the two solutions.)
The issue is resolved now. thank you.