0

On Parse.com, I have a class named ImagesEntry with a column named ImageFile that has images saved.

I have this code on android to read every row and return the images but it returns null.

    ParseFile[] getImagesFromParseCloudDB() {                

            ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(
                    "ImagesEntry");

            query.orderByDescending("_created_at");
            try {
                ob = query.find(); // 'List<ParseObject> ob' initialzed above OnCreate
            } catch (ParseException e) {
                Log.e("Error", e.getMessage());
                e.printStackTrace();
            }

            int i = 0;

            for (ParseObject images : ob) {
                // imagesFromDB is an array of type 'ParseFile'                
                imagesFromDB[i] = (ParseFile)images.getParseFile("ImageFile");
                i++;        
            }

            return imagesFromDB;
        }

Any pointers on what wrong am I doing ?

2 Answers 2

1

I think the reason for this is that getParseFile() doesn't request actual file. According to docs

function will not perform a network request

You need to add call ParseFile.getDataInBackground() or ParseFile.getData() to get actual data of the file. But don't try to spawn too many background loading tasks while iterating through array - you'll get exception if your array's size would larger than PoolSize of ExecutorService used by Parse. Consider creating some background task and synchronous execution of getData() request or customizing ExecutorService for Parse.

Sign up to request clarification or add additional context in comments.

Comments

0

First of all, this string "_created_at" is wrong for me. In my app I have "createdAt" and works fine.

I recommend you first get all ID in a List and use my code (it works for me):

ParseQuery query = new ParseQuery("Your_class_name");
                    query.getInBackground(imagenID, new GetCallback() {
                        @Override
                        public void done(ParseObject parseObject, ParseException e) {

                        }

                        @Override
                        public void done(Object o, Throwable throwable) {
                            ParseObject object = (ParseObject) o;
                            ParseFile foto = (ParseFile) object.get("Your_column_name");
                            foto.getDataInBackground(new GetDataCallback() {
                                @Override
                                public void done(byte[] bytes, ParseException e) {
                                    if (e == null) {
                                        //do things with this bytes
                                    } else {
                                        Toast.makeText(getApplicationContext(), "Error al descargar la foto", Toast.LENGTH_SHORT).show();
                                        e.printStackTrace();
                                    }
                                }
                            });

                        }
                    });
                }

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.