How to save and get profile picture on Parse.com?

I am very new to parse.com. I have a watch search, how to create a profile picture for the user, and I came up with no result. I know how to upload an image on Parse.com, but I don't know how to get it.

this is how i upload the image:

  // Save new user data into Parse.com Data Storage
                ParseUser user = new ParseUser();
                user.setUsername(usernametxt);
                user.setPassword(passwordtxt);
                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                // Compress image to lower quality scale 1 - 100
                photo.compress(Bitmap.CompressFormat.PNG, 100, stream);
                byte[] image = stream.toByteArray();

                // Create the ParseFile
                ParseFile file = new ParseFile(usernametxt + ".png", image);
                // Upload the image into Parse Cloud
                file.saveInBackground();

                // Create a New Class called "ImageUpload" in Parse
                ParseObject imgupload = new ParseObject("ImageUpload");

                // Create a column named "ImageName" and set the string
                imgupload.put("ImageName", usernametxt);

                // Create a column named "ImageFile" and insert the image
                imgupload.put("ImageFile", file);

                // Create the class and the columns
                imgupload.saveInBackground();

                // Show a simple toast message
                Toast.makeText(RegisterActivity.this, "Image Uploaded",
                        Toast.LENGTH_SHORT).show();

                user.signUpInBackground(new SignUpCallback() {
                   public void done(ParseException e) {
                        if (e == null) {
                            // Show a simple Toast message upon successful registration


                            Intent intent = new Intent(
                                    RegisterActivity.this,
                                    Welcome.class);
                            startActivity(intent);
                            finish();
                        } else {
                            Toast.makeText(getApplicationContext(),
                                   "Sign up Error", Toast.LENGTH_LONG)
                                    .show();
                        }
                    }
               });
           }

        }

This is how I get the image (don't work, throwing an exception): ParseQuery query = ParseQuery.getQuery ("ImageUpload"); query.whereEqualTo ("image_name", currentUser.getUsername ()); query.getFirstInBackground (new GetCallback () {

      public void done(ParseObject object, ParseException e) {
        if (object != null) {
            Toast.makeText(Welcome.this, currentUser.getUsername(),
                    Toast.LENGTH_SHORT).show();
            ParseFile file = (ParseFile)object.get("ImageFile");
            file.getDataInBackground(new GetDataCallback() {


            public void done(byte[] data, ParseException e) {
                if (e == null) {

                    bitmap=BitmapFactory.decodeByteArray(data, 0, data.length);
                    profilepic.setImageBitmap(bitmap);
                    //use this bitmap as you want

                } else {
                  // something went wrong
                }
              }
            });

        } else {
            Toast.makeText(getApplicationContext(), "Exception", Toast.LENGTH_SHORT) .show();

        }
      }
    });

if someone looks at the code and tries to let me know what I did wrong, it will help me a lot!

Sorry for my bad english.

+4
1

Parse - ParseUser ParseObject

Bitmap bitmapImage = ((BitmapDrawable) profilepic.getDrawable()).getBitmap(); // profile pic is the imageview
ByteArrayOutputStream stream = new ByteArrayOutputStream();
                    bitmapImage.compress(Bitmap.CompressFormat.JPEG, 40, stream);

                    byte[] byteArray = stream.toByteArray();

                    ParseFile file = new ParseFile("image.png", byteArray);

                    ParseObject Images = new ParseObject("Images");

                    Images.put("profilepic", file);
                    Images.put("username", Username);

                    Images.saveInBackground(new SaveCallback() {
                        @Override
                        public void done(ParseException e) {
                            if (e == null) {
                                Log.i("AppInfo", "Profile pic success");

                            } else {
                                Log.i("AppInfo", "Profile pic FAIL");
                            }
                        }
                    });

Parse

ParseQuery<ParseUser> imageQuery = new ParseUser.getQuery();
 imageQuery.whereEqualTo("objectId",ParseUser.getCurrentUser().getObjectId());
    imageQuery.findInBackground(new FindCallback<ParseObject>()
    {
        @Override
        public void done(List<ParseUser> users,ParseException e)
        {
            for(ParseUser user : users)
            {
                ParseFile UserProPicFile = object.getParseFile("ImageColumnName");
                byte[] byteArray = new byte[0];

                byteArray = UserProPicFile.getData();
                Bitmap ProselectBit = BitmapFactory.decodeByteArray(byteArray,0,byteArray.length); //Bitmap with [rofile picture
            }
        }
    });

,

0