Start a new topic

Retrieving related file from datastore collection - continued

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"); }

//Below is the code being executed to pull data from the Datastore

final Client mKinveyClient = new Client.Builder(this.getApplicationContext()).build();

Query myQuery = mKinveyClient.query();


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

myEvents.get(myQuery, new KinveyListCallback() {


public void onSuccess(WordEntity[] results) {

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

for (WordEntity entity : results) {

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

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

Log.v(TAG, entity.getUnknownKeys().toString()); //
Log.v(TAG, entity.getFile("image").getFileName()); //
//as there is no such file called "image" in the entity




public void onFailure(Throwable error) {...

The data in the Datastore looks to be in the correct format, when exported and imported in an online JSON checker, there are no issues identified with the formatting.

A work around would be to strip the _downloadURL value from the information in the UnknownKeys variable of the entity and then download the file, though this is messy and may lead the app to break in the future. Any suggestions/ideas/hints of what could be causing this would be much appreciated.
1 Comment

Two things:

First, use the AsyncLinkedData class instead of the AsyncAppData class for linking entities to files:

AsyncLinkedData myEvents = mKinveyClient.linkedData("words", WordEntity.class);

Then, note that LinkedData extends AppData so the standard AppData methods are inherited, but that's not what you want. The linkedData methods take a third new parameter, which is either an `UploadProgressListener` (for saves) or a `DownloadProgressListener` (for gets).

myEvents.get(myQuery, new KinveyListCallback() {


public void onSuccess(WordEntity[] results) { ... }


public void onFailure(Throwable error) {...}},

new DownloadProgressListener(){


public void progressChanged(MediaHttpUploader uploader) throws IOException {

//download progress changed!



public void onSuccess(Void result) {

//download complete!



public void onFailure(Throwable error) {

//something went wrong!



Also, you can pass `null` as a third parameter to linkedData methods if you do not need to know about file upload/download progress.
Login or Signup to post a comment