1

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.

2
  • do you are setting the Id? Commented Dec 15, 2015 at 21:06
  • yes, the parseObject id, here: parseObject.setObjectId("someId");. Anyway (if that failed from some reason) the Parse would generate id for me, and I should still be able at least see that class on dashboard, right? Commented Dec 15, 2015 at 21:09

2 Answers 2

1

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());
                    }
                }
            });
Sign up to request clarification or add additional context in comments.

4 Comments

I tried that. You can see that inside parseFile.saveInBackground(...) I am doing parseObject.saveInBackground. I tried saving parseObject only (did not work), and then tried chaining file and object, and from some reason i pasted that chained version code.
@Gudin Nowhere in your code you have posted do you save your ParseObject. Inside your parseFile.saveInBackground() you have another parseFile.saveInBackground() If this is not the correct code that you are having problems with then please update your post with the correct code.
Damn I'm so blind. Autocomplete got me there. Thank you for your help.
yes its always the small things that cause the most problems. Glad it worked.
0

I think that you would to do something like this:

// Create the ParseFile
ParseFile parseFile = new ParseFile("somefile.png", data);
file.saveInBackground();

ParseObject imgupload = new ParseObject("photo");
imgupload.put("ImageName", "somefile");
imgupload.put("photo1", parseFile);
imgupload.saveInBackground();

So, your query:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.