Got the above idea from the following post.
The above working with a file in an erpnext app.
My problem is in the gui of erpnext, there is a Server script doctype.
An api can be created there and the above solution does not seem to work in the gui Server Script of erpnext.
I hope I am using the correct terms.
I am not a programmer.