how to get file from parse.com in android?

2019-08-29 11:00发布

问题:

here is my db structure of purchased_item

and here is my image table

i want to get file FFNglxekCv

ParseQuery<ParseObject> query = ParseQuery.getQuery(KEY_MASTER_PURCHASED_ITEM);
    ParseUser currentUser = ParseUser.getCurrentUser();


    user.setObjectId(currentUser.getObjectId());*/

    query.whereEqualTo(KEY_PURCHASED_BY, currentUser);
    query.findInBackground(new FindCallback<ParseObject>() {
        public void done(List<ParseObject> parseObjectList, ParseException e) {
            hideProgressDialog();
            if (e == null) {

                if (!parseObjectList.isEmpty()) {

                    for (int i = 0; i < parseObjectList.size(); i++) {

                        ParseObject parseObject = parseObjectList.get(i);

                     // ParseFile parseFile =(ParseFile) parseObject.getParseFile("image");


                        Log.e(TAG,TAG);
                    }
                }

            } else {
                if (!e.getLocalizedMessage().equalsIgnoreCase(""))
                    showErrorToast(e.getLocalizedMessage(), true);
                else
                    showErrorToast(getString(R.string.no_response_from_server), true);
                Log.d(TAG, "Error: " + e.getMessage());
            }
        }
    });

i dont know how to get image from parse.com

回答1:

I'm using Back4App! Could you please try something like the below?

ParseQuery<ParseObject> query = ParseQuery.getQuery("Photo");
        query.whereEqualTo("objectId", FFNglxekCv);
        query.findInBackground(new FindCallback<ParseObject>() {
            @Override
            public void done(List<ParseObject> objects, ParseException e) {
                if(e==null){
                    for(ParseObject object : objects){
                        ParseFile file = (ParseFile) object.get("image");
                        file.getDataInBackground(new GetDataCallback() {
                            @Override
                            public void done(byte[] data, ParseException e) {
                                if(e==null){
                                    Bitmap bitmapImage = BitmapFactory.decodeByteArray(data, 0, data.length);
                                    ImageView image = new ImageView(getApplicationContext());
                                    image.setImageBitmap(bitmapImage);
                                    relativeLayout.addView(image);
                                }
                                else{
                                    Log.i("info", e.getMessage());
                                }
                            }
                        });
                    }
                }
                else{
                    Log.i("info", e.getMessage());
                }
            }
        });

Let I kow if it's working for you!