As of April 12th, you must go to Progress SupportLink to create new support cases or to access existing cases. Please, bookmark the SupportLink URL and use the new portal to contact the support team.
Retrieving related file from datastore collection - continued
S
Shane Lee
started a topic
over 9 years ago
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();
Log.v(TAG, entity.getUnknownKeys().toString()); // Log.v(TAG, entity.getFile("image").getFileName()); // //as there is no such file called "image" in the entity
}
}
@Override
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
E
Edward
said
over 9 years ago
Two things:
First, use the AsyncLinkedData class instead of the AsyncAppData class for linking entities to files:
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() {
@Override
public void onSuccess(WordEntity[] results) { ... }
@Override
public void onFailure(Throwable error) {...}},
new DownloadProgressListener(){
@Override
public void progressChanged(MediaHttpUploader uploader) throws IOException {
//download progress changed!
}
@Override
public void onSuccess(Void result) {
//download complete!
}
@Override
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.
Shane Lee
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();
myQuery.equals("_id","1");
AsyncAppData myEvents = mKinveyClient.appData("words", WordEntity.class);
myEvents.get(myQuery, new KinveyListCallback() {
@Override
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
}
}
@Override
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.