Search code examples
androidparse-platform

Check if a ParseFile is empty


My ParseUser class has a custom column called "profile_photo" which is a ParseFile of a photo. I have attached a photo file to a ParseUser instance and I can see on my app users dashboard that the profile_photo column for that user is filled with that file and the other users have "undefined" set for that column, as expected. Now on my code I need to check if a user has a profile photo attached or not. How do I do this. I have tried to check that using the isDataAvailable() but it always returns true even if the value for profile_photo is "undefined" on the dashboard. I have also tried the following:

ParseFile photo = user.get("profile_photo");
photo.getDataInBackground(new GetDataCallback() { 
   @Override public void done(byte[] data, ParseException pfe) { 
      if(pfe == null) { 
         // byte array data always returns something! data.length > 0, always, even for undefined... 
       }
   }
});

But as you can see by the comments, the data array is never empty even if the ParseFile attached to the ParseUser in question is "undefined".

I would much appreciate if you could tell me or indicate me a way to clearly identify if a parsefile is empty or not.

Best Regards


Solution

  • You are using the wrong method to obtain your file. If you use get("column_name") on a column which is ParseFile, this method will return the file id. You should instead use

    ParseFile file = object.getParseFile("column_name");
    

    which will return null if the file is undefined.