How do I create a file (.apk) from a url in Jaggery?

I have app store and apps have their url. I want to download apks from these urls to my jaggery server. Although below code (my first solution) create myApp.apk successfully, it doesn't work correctly.

I tried below code first,

var url  = "";
var data = get(url, {});    

var file = new File("myApp.apk");"w");


when i print the value it looks like

I tried it too,
var file = new File("");


Can anyone help me?


source to share

2 answers


files are Android application files and are expected to start with PK

because they are actually zip archives!

They are not meant to be unpacked, although you can do so to see some of the application's resources (but there are ways to reverse engineer .apk

files like Apktool if that's what you're looking for).



According to the jaggery documentation , file.write writes the string representation of an object to a file. So why are you getting an apk file that cannot be installed.

However, you can make it work with copyURLToFile in the apache commons-io java library as follows, since jaggery supports java itself and all WSO2 products have the apache commons-io library in their classpath.

    var JFileUtils =;
    var JUrl =;
    var JFile =;
    var url  = new JUrl("");
    JFileUtils.copyURLToFile(url, new JFile("myApp.apk"));


Your file will be saved in the $ CARBON_HOME directory by default, unless you provide a relative or absolute file path.



All Articles