Hi Ashish,
Glad you’ve found the article useful and are using Azle on your projects.
You can download files in your browser using Azle’s download_file function:
az.download_file({
"filename" : "my_file",
"file_path" : "img/my_image.png"
})
If you want to allow a user to download a file by clicking on a button you can first add the button:
az.add_button("target_class", target_instance, {
"this_class" : "my_button",
"text" : "DOWNLOAD FILE"
})
…and then add a click event to the button that calls download_file:
az.add_event("my_button", 1, {
"type": "click",
"function": function() {
az.download_file({
"filename": "my_file",
"file_path": "img/my_image.png"
})
}
})
Here is me doing this with one of my images:
You can also use Azle’s download_text_as_file function if you want to write some text output to a file that a user can download:
az.download_text_as_file({
"filename" : "my_text",
"text" : "This is some text inside a file."
})
Here’s a Fiddle.
Let me know if that helps, or if you have any other questions. Happy to help out.