jdubicki jdubicki - 2 years ago 99
Java Question

Cloudboost File url is null for Android Java

I am having a little problem getting all of the file info from my Cloudboost file object. Here is the code that I am using to get the id, name and url of the file. The problem is that I can get back the id and the name; however, the url is is null and I don't know why or how to fix it. Any ideas??

class FileQuery extends AsyncTask<Void, Void, Void> {
protected Void doInBackground(Void... params) {
CloudQuery query = new CloudQuery("Pubs");
query.equalTo("id", "U1YV132B");
try {
query.find(new CloudObjectArrayCallback() {
public void done(CloudObject[] x, CloudException t) throws CloudException {
if (x != null) {
for (int i = 0; i < x.length; i++) {
final CloudFile f = new CloudFile(x[i].getDocument());
f.fetch(new CloudFileArrayCallback() {
public void done(CloudFile[] x, CloudException t) throws CloudException {
Log.d("dozer74", "File Id: " + f.getId()); // This will print out
Log.d("dozer74", "File Name: " + f.getFileName()); // This will print out
Log.d("dozer74", "File URL: " + f.getFileUrl()); // This is null
} catch (CloudException e) {
return null;

Here is how I call this class

new FileQuery().execute();

Answer Source

Assuming column file in table Pubs is actually of type File and you saved a CloudFile to CloudBoost before saving it to Pubs.
You should now access your CloudFile like this instead:

final CloudFile file=new CloudFile(x[i].getDocument().getJSONObject("file"));

This is because your line

final CloudFile f = new CloudFile(x[i].getDocument());


  1. returns the body of the CloudObject
  2. creates CloudFile using the output of step #1 above

You are missing one step in between as indicated below:

1.get the body of CloudObject

2. retrieve the body of a CloudFile under column file inside the CloudObject

3. Create CloudFile using the ouput of step #2 above.

CloudObject.getFile([columnName]) appears as one of the improvements to make this operation easier in JavaSDK-1.0.3 which you should be able to clone soon from the CloudBoost repo.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download