How to Download Assets File with andorid?

34 views
Skip to first unread message

michio

unread,
Nov 8, 2016, 3:40:40 PM11/8/16
to BaasBox

Hi guys, 

i made an asset with a json file for public access , how can i download it with baasbox android sdk?

i used api and did something like this : 

BaasAsset.fetchData("companies", new BaasHandler<JsonObject>() {
@Override
public void handle(BaasResult<JsonObject> baasResult) {
if(baasResult.isSuccess()){
JsonObject json = null;
try {
json = baasResult.get();
} catch (BaasException e) {
e.printStackTrace();
}

String myJson = json.encode();
Log.d("ASSET" , myJson);

}
else{

}
}
});

but the log shows me an url , please help me.

Thanks , michio

ymir

unread,
Nov 9, 2016, 11:20:36 AM11/9/16
to BaasBox
Hi michio,

with the previous call, actually, you don't get the json object but the meta data associated with the asset.
In order to download the content of the json, you should use streamAsset() method.
In the callback you should be able to transform the received byte array into a json object.
Hope this solves your problem.

ymir


michio

unread,
Nov 10, 2016, 4:55:36 PM11/10/16
to BaasBox
Thank you ymir, 
streamAsset() method call solved it.
Reply all
Reply to author
Forward
0 new messages