Start a new topic

Retrieving related file from datastore collection

I have followed the Android Files Guide to create a LinkedGenericJson entity with the putFile method to attach related file information to the entity. However, this is not working for me.



From the debugger I can see that when I issue a get from the AsynAppData class to extract data from my Datastore collection, I can successfully pull all the data from the collection, including field values and even the related file information as well. The problem is that my LinkedgenericJson entity does not recognise the related file json data as File information. It stores it as an "Unknown key" value in my entity.



Below is my entity construct. I can successfully map all the other fields to the data being pulled from the datastore, only the File data is being treated as an unknown key.



public class WordEntity extends LinkedGenericJson{



@Key("_id")

private String id;



@Key("english_word")

private String english;



@Key("foreign_word")

private String foreign;



@Key("mnemonic_story")

private String story;



@Key("focus_word")

private String focus;



public WordEntity(){

putFile("image");

}

Hey that looks correct so far but I'm going to need some more information--



That looks correct, can you post the code you use to access linkedData?
Thanks for the prompt response. Here is the code.



AsyncAppData myevents = mKinveyClient.appData("words", WordEntity.class);

myevents.get(new KinveyListCallback() {

@Override

public void onSuccess(WordEntity[] result) {

Log.v(TAG, "received "+ result.length + " events");

for (WordEntity entity : result) {

Log.v(TAG, entity.toString());

Log.v(TAG, entity.getEnglish());

Log.v(TAG, entity.getUnknownKeys().toString()); //
//Log.v(TAG, entity.getFile("image").getFileName());
}

}

@Override

public void onFailure(Throwable error) {

Log.e(TAG, "failed to fetch all", error);

}

});
Post seems to have reformatted my text. Try again.



```AsyncAppData myevents = mKinveyClient.appData("words", WordEntity.class);

myevents.get(new KinveyListCallback() {

@Override

public void onSuccess(WordEntity[] result) {

Log.v(TAG, "received "+ result.length + " events");

for (WordEntity entity : result) {

Log.v(TAG, entity.toString());

Log.v(TAG, entity.getEnglish());

Log.v(TAG, entity.getUnknownKeys().toString()); //
//Log.v(TAG, entity.getFile("image").getFileName());
}

@Override

public void onFailure(Throwable error) {

Log.e(TAG, "failed to fetch all", error);

}

});```
Try removing:



@Key("_id") private String id;



From your entity.



If/When the callback is success, I saw that my collection was null and that was crashing my app. I simply removed the _Id field that Kinvey automatically gives you when you create a new row.



Hope it helps
Login or Signup to post a comment