Search code examples
androidparse-platform

Parse.com not saving ParseObjects


I am trying to upload file to Parse cloud.

final ParseFile parseFile = new ParseFile("somefile.png", data);
    parseFile.saveInBackground(new SaveCallback() {
        @Override
        public void done(ParseException e) {
            if (e == null){

                ParseObject parseObject = new ParseObject("photo");
                parseObject.setObjectId("someId");
                parseObject.put("photo1", parseFile);
                parseFile.saveInBackground(new SaveCallback() {
                    @Override
                    public void done(ParseException e) {
                        if (e==null){
                            Log.d(TAG, "Save done");
                        } else {
                            Log.d(TAG, "ex" + e.getMessage());
                        }
                    }
                });

            } else {
                Log.d("USER", "file save ex" + e.getMessage());
            }
        }
    });

This will run and show successfully and show "Save done" log. But when i go to Parse dashboard i don't see anything changing in data. I tried to retrieve object:

ParseQuery<ParseObject> query = ParseQuery.getQuery("photo");
    query.getInBackground("someId", new GetCallback<ParseObject>() {
        @Override
        public void done(ParseObject object, ParseException e) {
            if (e == null){
                Log.d("USER", "OK");
            } else {
                Log.d("USER", "ex" + e.getMessage());
            }
        }
    });

But i get ParseException: no results found for query.


Solution

  • Looks like you are saving the parseFile twice and forgetting to save the parse object that you placed the file in.

    change this

    parseFile.saveInBackground(new SaveCallback() {
                    @Override
                    public void done(ParseException e) {
                        if (e==null){
                            Log.d(TAG, "Save done");
                        } else {
                            Log.d(TAG, "ex" + e.getMessage());
                        }
                    }
                });
    

    to this

    parseObject.saveInBackground(new SaveCallback() {
                    @Override
                    public void done(ParseException e) {
                        if (e==null){
                            Log.d(TAG, "Save done");
                        } else {
                            Log.d(TAG, "ex" + e.getMessage());
                        }
                    }
                });