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  = "http://img.xxx.com/006/someApp.apk";
var data = get(url, {});    

var file = new File("myApp.apk");
    file.open("w");
    file.write(data.data);
    file.close(); 

      


when i print the data.data value it looks like

data.data


I tried it too,
var file = new File("http://img.xxx.com/006/someApp.apk");
file.saveAs("myApp.txt");

      

Can anyone help me?

+3


source to share


2 answers


.apk

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).

0


source


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 = Packages.org.apache.commons.io.FileUtils;
    var JUrl = Packages.java.net.URL;
    var JFile = Packages.java.io.File;
    var url  = new JUrl("http://img.xxx.com/006/someApp.apk");
    JFileUtils.copyURLToFile(url, new JFile("myApp.apk"));
    print("done");
%>

      

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

0


source







All Articles